Chromium Code Reviews| Index: components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc |
| diff --git a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc |
| index 0109d4fc1f1dcc9f8fe254c426ad0cbb73989521..7f66b6d609ac732ca9728a2aef8b1218643031f7 100644 |
| --- a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc |
| +++ b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc |
| @@ -2,19 +2,20 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "components/subresource_filter/content/browser/content_subresource_filter_driver_factory.h" |
|
nasko
2017/02/16 18:47:58
nit: An empty line after this header.
clamy
2017/02/17 17:34:52
Done.
|
| #include "base/macros.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/metrics/field_trial.h" |
| #include "base/test/histogram_tester.h" |
| #include "components/safe_browsing_db/util.h" |
| #include "components/subresource_filter/content/browser/content_subresource_filter_driver.h" |
| -#include "components/subresource_filter/content/browser/content_subresource_filter_driver_factory.h" |
| #include "components/subresource_filter/content/common/subresource_filter_messages.h" |
| #include "components/subresource_filter/core/browser/subresource_filter_client.h" |
| #include "components/subresource_filter/core/browser/subresource_filter_features.h" |
| #include "components/subresource_filter/core/browser/subresource_filter_features_test_support.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/common/browser_side_navigation_policy.h" |
| +#include "content/public/test/navigation_simulator.h" |
| #include "content/public/test/test_renderer_host.h" |
| #include "content/public/test/web_contents_tester.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| @@ -179,13 +180,10 @@ class ContentSubresourceFilterDriverFactoryTest |
| web_contents(), base::WrapUnique(client())); |
| driver_ = new MockSubresourceFilterDriver(main_rfh()); |
| SetDriverForFrameHostForTesting(main_rfh(), driver()); |
| - // Add a subframe. |
| content::RenderFrameHostTester* rfh_tester = |
| content::RenderFrameHostTester::For(main_rfh()); |
| rfh_tester->InitializeRenderFrameIfNeeded(); |
| - subframe_rfh_ = rfh_tester->AppendChild("Child"); |
| - subframe_driver_ = new MockSubresourceFilterDriver(subframe_rfh()); |
| - SetDriverForFrameHostForTesting(subframe_rfh(), subframe_driver()); |
| + subframe_rfh_ = nullptr; |
| } |
| void SetDriverForFrameHostForTesting( |
| @@ -217,10 +215,14 @@ class ContentSubresourceFilterDriverFactoryTest |
| bool expected_activation) { |
| base::HistogramTester tester; |
| EXPECT_CALL(*client(), ToggleNotificationVisibility(false)).Times(1); |
| - content::RenderFrameHostTester* rfh_tester = |
| - content::RenderFrameHostTester::For(main_rfh()); |
| - rfh_tester->SimulateNavigationStart(navigation_chain.front()); |
| + std::unique_ptr<content::NavigationSimulator> navigation_simulator = |
| + content::NavigationSimulator::CreateRendererInitiated( |
| + navigation_chain.front(), main_rfh()); |
| + navigation_simulator->SetReferrer(referrer); |
| + navigation_simulator->SetTransition(transition); |
| + navigation_simulator->Start(); |
| + |
| if (blacklisted_urls.front()) { |
| factory()->OnMainResourceMatchedSafeBrowsingBlacklist( |
| navigation_chain.front(), navigation_chain, threat_type, |
| @@ -234,23 +236,25 @@ class ContentSubresourceFilterDriverFactoryTest |
| factory()->OnMainResourceMatchedSafeBrowsingBlacklist( |
| url, navigation_chain, threat_type, threat_type_metadata); |
| } |
| - rfh_tester->SimulateRedirect(url); |
| + navigation_simulator->Redirect(url); |
| } |
| EXPECT_CALL(*driver(), |
| ActivateForProvisionalLoad(::testing::_, ::testing::_, |
| expected_measure_performance())) |
| .Times(expected_activation); |
| - // TODO(crbug.com/688393): remove the call to |
| - // ReadyToCommitNavigationInternal once WCO::ReadyToCommitNavigation is |
| - // invoked consistently for tests in PlzNavigate and non-PlzNavigate. |
| - if (!content::IsBrowserSideNavigationEnabled()) { |
| - factory()->ReadyToCommitNavigationInternal( |
| - main_rfh(), navigation_chain.back(), referrer, transition); |
| - } |
| - |
| - rfh_tester->SimulateNavigationCommit(navigation_chain.back()); |
| + navigation_simulator->Commit(); |
| ::testing::Mock::VerifyAndClearExpectations(driver()); |
| + driver_ = new MockSubresourceFilterDriver(main_rfh()); |
| + SetDriverForFrameHostForTesting(main_rfh(), driver()); |
| + |
| + // Add a subframe. |
| + content::RenderFrameHostTester* rfh_tester = |
| + content::RenderFrameHostTester::For(main_rfh()); |
| + subframe_rfh_ = rfh_tester->AppendChild("Child"); |
| + subframe_driver_ = new MockSubresourceFilterDriver(subframe_rfh()); |
| + SetDriverForFrameHostForTesting(subframe_rfh(), subframe_driver()); |
| + |
| if (expected_pattern != EMPTY) { |
| EXPECT_THAT(tester.GetAllSamples(kMatchesPatternHistogramName), |
| ::testing::ElementsAre(base::Bucket(expected_pattern, 1))); |
| @@ -331,8 +335,10 @@ class ContentSubresourceFilterDriverFactoryTest |
| ::testing::_, ::testing::_, ::testing::_)) |
| .Times(0); |
| EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); |
| - content::RenderFrameHostTester::For(main_rfh()) |
| - ->SimulateNavigationCommit(GURL(kExampleUrl)); |
| + std::unique_ptr<content::NavigationSimulator> navigation_simulator = |
| + content::NavigationSimulator::CreateRendererInitiated(GURL(kExampleUrl), |
| + main_rfh()); |
| + navigation_simulator->CommitSamePage(); |
| ::testing::Mock::VerifyAndClearExpectations(driver()); |
| ::testing::Mock::VerifyAndClearExpectations(client()); |
| } |
| @@ -550,12 +556,6 @@ TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| } |
| TEST_F(ContentSubresourceFilterDriverFactoryTest, WhitelistSiteOnReload) { |
| - // TODO(crbug.com/688393): enable this test for PlzNavigate once |
| - // WCO::ReadyToCommitNavigation is invoked consistently for tests in |
| - // PlzNavigate and non-PlzNavigate. |
| - if (content::IsBrowserSideNavigationEnabled()) |
| - return; |
| - |
| const struct { |
| content::Referrer referrer; |
| ui::PageTransition transition; |