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 <memory> | 5 #include <memory> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/feature_list.h" | 8 #include "base/feature_list.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/test/scoped_feature_list.h" | 13 #include "base/test/scoped_feature_list.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
15 #include "chrome/browser/after_startup_task_utils.h" | 15 #include "chrome/browser/after_startup_task_utils.h" |
16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
17 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
18 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" | 18 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" |
19 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" | 19 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" |
20 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h" | 20 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h" |
21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
22 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
23 #include "components/prefs/testing_pref_service.h" | 23 #include "components/prefs/testing_pref_service.h" |
24 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | 24 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
25 #include "components/subresource_filter/content/browser/content_ruleset_service.
h" | 25 #include "components/subresource_filter/content/browser/content_ruleset_service.
h" |
26 #include "components/subresource_filter/content/browser/content_subresource_filt
er_driver_factory.h" | |
27 #include "components/subresource_filter/content/browser/fake_safe_browsing_datab
ase_manager.h" | 26 #include "components/subresource_filter/content/browser/fake_safe_browsing_datab
ase_manager.h" |
28 #include "components/subresource_filter/core/browser/ruleset_service.h" | 27 #include "components/subresource_filter/core/browser/ruleset_service.h" |
29 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" | 28 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" |
30 #include "components/subresource_filter/core/browser/subresource_filter_features
_test_support.h" | 29 #include "components/subresource_filter/core/browser/subresource_filter_features
_test_support.h" |
31 #include "components/subresource_filter/core/common/test_ruleset_creator.h" | 30 #include "components/subresource_filter/core/common/test_ruleset_creator.h" |
32 #include "content/public/browser/navigation_throttle.h" | 31 #include "content/public/browser/navigation_throttle.h" |
33 #include "content/public/test/navigation_simulator.h" | 32 #include "content/public/test/navigation_simulator.h" |
34 #include "content/public/test/test_renderer_host.h" | 33 #include "content/public/test/test_renderer_host.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
36 #include "url/gurl.h" | 35 #include "url/gurl.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 subresource_filter::testing::TestRulesetPair test_ruleset_pair; | 94 subresource_filter::testing::TestRulesetPair test_ruleset_pair; |
96 ruleset_creator.CreateRulesetToDisallowURLsWithPathSuffix( | 95 ruleset_creator.CreateRulesetToDisallowURLsWithPathSuffix( |
97 "disallowed.html", &test_ruleset_pair); | 96 "disallowed.html", &test_ruleset_pair); |
98 subresource_filter::testing::TestRulesetPublisher test_ruleset_publisher; | 97 subresource_filter::testing::TestRulesetPublisher test_ruleset_publisher; |
99 ASSERT_NO_FATAL_FAILURE( | 98 ASSERT_NO_FATAL_FAILURE( |
100 test_ruleset_publisher.SetRuleset(test_ruleset_pair.unindexed)); | 99 test_ruleset_publisher.SetRuleset(test_ruleset_pair.unindexed)); |
101 | 100 |
102 // Set up the tab helpers. | 101 // Set up the tab helpers. |
103 InfoBarService::CreateForWebContents(web_contents()); | 102 InfoBarService::CreateForWebContents(web_contents()); |
104 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 103 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
| 104 ChromeSubresourceFilterClient::CreateForWebContents(web_contents()); |
105 | 105 |
106 std::unique_ptr<ChromeSubresourceFilterClient> subresource_filter_client( | |
107 new ChromeSubresourceFilterClient(web_contents())); | |
108 client_ = subresource_filter_client.get(); | |
109 subresource_filter::ContentSubresourceFilterDriverFactory:: | |
110 CreateForWebContents(web_contents(), | |
111 std::move(subresource_filter_client)); | |
112 base::RunLoop().RunUntilIdle(); | 106 base::RunLoop().RunUntilIdle(); |
113 } | 107 } |
114 | 108 |
115 void TearDown() override { | 109 void TearDown() override { |
116 fake_safe_browsing_database_ = nullptr; | 110 fake_safe_browsing_database_ = nullptr; |
117 TestingBrowserProcess::GetGlobal()->safe_browsing_service()->ShutDown(); | 111 TestingBrowserProcess::GetGlobal()->safe_browsing_service()->ShutDown(); |
118 | 112 |
119 // Must explicitly set these to null and pump the run loop to ensure that | 113 // Must explicitly set these to null and pump the run loop to ensure that |
120 // all cleanup related to these classes actually happens. | 114 // all cleanup related to these classes actually happens. |
121 TestingBrowserProcess::GetGlobal()->SetRulesetService(nullptr); | 115 TestingBrowserProcess::GetGlobal()->SetRulesetService(nullptr); |
(...skipping 24 matching lines...) Expand all Loading... |
146 content::RenderFrameHostTester::For(parent)->AppendChild("subframe"); | 140 content::RenderFrameHostTester::For(parent)->AppendChild("subframe"); |
147 return SimulateNavigateAndCommit( | 141 return SimulateNavigateAndCommit( |
148 GURL("https://example.test/disallowed.html"), subframe); | 142 GURL("https://example.test/disallowed.html"), subframe); |
149 } | 143 } |
150 | 144 |
151 void ConfigureAsSubresourceFilterOnlyURL(const GURL& url) { | 145 void ConfigureAsSubresourceFilterOnlyURL(const GURL& url) { |
152 fake_safe_browsing_database_->AddBlacklistedUrl( | 146 fake_safe_browsing_database_->AddBlacklistedUrl( |
153 url, safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER); | 147 url, safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER); |
154 } | 148 } |
155 | 149 |
156 ChromeSubresourceFilterClient* client() { return client_; } | 150 ChromeSubresourceFilterClient* client() { |
| 151 return ChromeSubresourceFilterClient::FromWebContents(web_contents()); |
| 152 } |
157 | 153 |
158 private: | 154 private: |
159 base::ScopedTempDir ruleset_service_dir_; | 155 base::ScopedTempDir ruleset_service_dir_; |
160 TestingPrefServiceSimple pref_service_; | 156 TestingPrefServiceSimple pref_service_; |
161 base::test::ScopedFeatureList scoped_feature_list_; | 157 base::test::ScopedFeatureList scoped_feature_list_; |
162 ScopedSubresourceFilterConfigurator scoped_configuration_; | 158 ScopedSubresourceFilterConfigurator scoped_configuration_; |
163 | 159 |
164 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_; | 160 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_; |
165 | 161 |
166 ChromeSubresourceFilterClient* client_ = nullptr; | |
167 | |
168 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterTest); | 162 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterTest); |
169 }; | 163 }; |
170 | 164 |
171 TEST_F(SubresourceFilterTest, SimpleAllowedLoad) { | 165 TEST_F(SubresourceFilterTest, SimpleAllowedLoad) { |
172 GURL url("https://example.test"); | 166 GURL url("https://example.test"); |
173 SimulateNavigateAndCommit(url, main_rfh()); | 167 SimulateNavigateAndCommit(url, main_rfh()); |
174 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh())); | 168 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh())); |
175 EXPECT_FALSE(client()->did_show_ui_for_navigation()); | 169 EXPECT_FALSE(client()->did_show_ui_for_navigation()); |
176 } | 170 } |
177 | 171 |
178 TEST_F(SubresourceFilterTest, SimpleDisallowedLoad) { | 172 TEST_F(SubresourceFilterTest, SimpleDisallowedLoad) { |
179 GURL url("https://example.test"); | 173 GURL url("https://example.test"); |
180 ConfigureAsSubresourceFilterOnlyURL(url); | 174 ConfigureAsSubresourceFilterOnlyURL(url); |
181 SimulateNavigateAndCommit(url, main_rfh()); | 175 SimulateNavigateAndCommit(url, main_rfh()); |
182 EXPECT_FALSE(CreateAndNavigateDisallowedSubframe(main_rfh())); | 176 EXPECT_FALSE(CreateAndNavigateDisallowedSubframe(main_rfh())); |
183 EXPECT_TRUE(client()->did_show_ui_for_navigation()); | 177 EXPECT_TRUE(client()->did_show_ui_for_navigation()); |
184 } | 178 } |
OLD | NEW |