| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/subresource_filter/content/browser/subframe_navigation_filt
ering_throttle.h" | 5 #include "components/subresource_filter/content/browser/subframe_navigation_filt
ering_throttle.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter.h" | 14 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter.h" |
| 15 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter_test_utils.h" |
| 15 #include "components/subresource_filter/core/common/activation_level.h" | 16 #include "components/subresource_filter/core/common/activation_level.h" |
| 16 #include "components/subresource_filter/core/common/activation_state.h" | 17 #include "components/subresource_filter/core/common/activation_state.h" |
| 17 #include "components/subresource_filter/core/common/test_ruleset_creator.h" | 18 #include "components/subresource_filter/core/common/test_ruleset_creator.h" |
| 18 #include "content/public/browser/navigation_handle.h" | 19 #include "content/public/browser/navigation_handle.h" |
| 19 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
| 20 #include "content/public/test/navigation_simulator.h" | 21 #include "content/public/test/navigation_simulator.h" |
| 21 #include "content/public/test/test_renderer_host.h" | 22 #include "content/public/test/test_renderer_host.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 namespace subresource_filter { | 25 namespace subresource_filter { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // Make the blocking task runner run on the current task runner for the | 66 // Make the blocking task runner run on the current task runner for the |
| 66 // tests, to ensure that the NavigationSimulator properly runs all necessary | 67 // tests, to ensure that the NavigationSimulator properly runs all necessary |
| 67 // tasks while waiting for throttle checks to finish. | 68 // tasks while waiting for throttle checks to finish. |
| 68 dealer_handle_ = base::MakeUnique<VerifiedRulesetDealer::Handle>( | 69 dealer_handle_ = base::MakeUnique<VerifiedRulesetDealer::Handle>( |
| 69 base::MessageLoop::current()->task_runner()); | 70 base::MessageLoop::current()->task_runner()); |
| 70 dealer_handle_->SetRulesetFile( | 71 dealer_handle_->SetRulesetFile( |
| 71 testing::TestRuleset::Open(test_ruleset_pair_.indexed)); | 72 testing::TestRuleset::Open(test_ruleset_pair_.indexed)); |
| 72 ruleset_handle_ = | 73 ruleset_handle_ = |
| 73 base::MakeUnique<VerifiedRuleset::Handle>(dealer_handle_.get()); | 74 base::MakeUnique<VerifiedRuleset::Handle>(dealer_handle_.get()); |
| 74 | 75 |
| 76 testing::TestActivationStateCallbackReceiver activation_state; |
| 75 parent_filter_ = base::MakeUnique<AsyncDocumentSubresourceFilter>( | 77 parent_filter_ = base::MakeUnique<AsyncDocumentSubresourceFilter>( |
| 76 ruleset_handle_.get(), | 78 ruleset_handle_.get(), |
| 77 AsyncDocumentSubresourceFilter::InitializationParams( | 79 AsyncDocumentSubresourceFilter::InitializationParams( |
| 78 document_url, ActivationLevel::ENABLED, | 80 document_url, ActivationLevel::ENABLED, |
| 79 false /* measure_performance */), | 81 false /* measure_performance */), |
| 80 base::Bind([](ActivationState state) { | 82 activation_state.GetCallback(), base::OnceClosure()); |
| 81 EXPECT_EQ(ActivationLevel::ENABLED, state.activation_level); | |
| 82 }), | |
| 83 base::OnceClosure()); | |
| 84 RunUntilIdle(); | 83 RunUntilIdle(); |
| 84 activation_state.ExpectReceivedOnce( |
| 85 ActivationState(ActivationLevel::ENABLED)); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void RunUntilIdle() { base::RunLoop().RunUntilIdle(); } | 88 void RunUntilIdle() { base::RunLoop().RunUntilIdle(); } |
| 88 | 89 |
| 89 void CreateTestSubframeAndInitNavigation(const GURL& first_url, | 90 void CreateTestSubframeAndInitNavigation(const GURL& first_url, |
| 90 content::RenderFrameHost* parent) { | 91 content::RenderFrameHost* parent) { |
| 91 content::RenderFrameHost* render_frame = | 92 content::RenderFrameHost* render_frame = |
| 92 content::RenderFrameHostTester::For(parent)->AppendChild( | 93 content::RenderFrameHostTester::For(parent)->AppendChild( |
| 93 base::StringPrintf("subframe-%s", first_url.spec().c_str())); | 94 base::StringPrintf("subframe-%s", first_url.spec().c_str())); |
| 94 navigation_simulator_ = | 95 navigation_simulator_ = |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 InitializeDocumentSubresourceFilter(GURL("https://example.test")); | 184 InitializeDocumentSubresourceFilter(GURL("https://example.test")); |
| 184 content::RenderFrameHostTester::For(parent_subframe) | 185 content::RenderFrameHostTester::For(parent_subframe) |
| 185 ->SimulateNavigationCommit(test_url); | 186 ->SimulateNavigationCommit(test_url); |
| 186 | 187 |
| 187 CreateTestSubframeAndInitNavigation( | 188 CreateTestSubframeAndInitNavigation( |
| 188 GURL("https://example.test/disallowed.html"), parent_subframe); | 189 GURL("https://example.test/disallowed.html"), parent_subframe); |
| 189 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 190 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
| 190 } | 191 } |
| 191 | 192 |
| 192 } // namespace subresource_filter | 193 } // namespace subresource_filter |
| OLD | NEW |