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

Side by Side Diff: chrome/browser/subresource_filter/subresource_filter_unittest.cc

Issue 2859783002: [subresource_filter] Make website setting existence imply site activation (Closed)
Patch Set: rebase Created 3 years, 7 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 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/profiles/profile.h"
18 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" 19 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
19 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" 20 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
21 #include "chrome/browser/subresource_filter/subresource_filter_content_settings_ manager.h"
22 #include "chrome/browser/subresource_filter/subresource_filter_profile_context.h "
23 #include "chrome/browser/subresource_filter/subresource_filter_profile_context_f actory.h"
20 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h" 24 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h"
21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
22 #include "chrome/test/base/testing_browser_process.h" 26 #include "chrome/test/base/testing_browser_process.h"
27 #include "chrome/test/base/testing_profile.h"
23 #include "components/prefs/testing_pref_service.h" 28 #include "components/prefs/testing_pref_service.h"
24 #include "components/safe_browsing_db/v4_protocol_manager_util.h" 29 #include "components/safe_browsing_db/v4_protocol_manager_util.h"
25 #include "components/subresource_filter/content/browser/content_ruleset_service. h" 30 #include "components/subresource_filter/content/browser/content_ruleset_service. h"
31 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h"
26 #include "components/subresource_filter/content/browser/fake_safe_browsing_datab ase_manager.h" 32 #include "components/subresource_filter/content/browser/fake_safe_browsing_datab ase_manager.h"
27 #include "components/subresource_filter/core/browser/ruleset_service.h" 33 #include "components/subresource_filter/core/browser/ruleset_service.h"
28 #include "components/subresource_filter/core/browser/subresource_filter_features .h" 34 #include "components/subresource_filter/core/browser/subresource_filter_features .h"
29 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h" 35 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h"
30 #include "components/subresource_filter/core/common/test_ruleset_creator.h" 36 #include "components/subresource_filter/core/common/test_ruleset_creator.h"
31 #include "content/public/browser/navigation_throttle.h" 37 #include "content/public/browser/navigation_throttle.h"
32 #include "content/public/test/navigation_simulator.h" 38 #include "content/public/test/navigation_simulator.h"
33 #include "content/public/test/test_renderer_host.h" 39 #include "content/public/test/test_renderer_host.h"
34 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
35 #include "url/gurl.h" 41 #include "url/gurl.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 153
148 void ConfigureAsSubresourceFilterOnlyURL(const GURL& url) { 154 void ConfigureAsSubresourceFilterOnlyURL(const GURL& url) {
149 fake_safe_browsing_database_->AddBlacklistedUrl( 155 fake_safe_browsing_database_->AddBlacklistedUrl(
150 url, safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER); 156 url, safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER);
151 } 157 }
152 158
153 ChromeSubresourceFilterClient* client() { 159 ChromeSubresourceFilterClient* client() {
154 return ChromeSubresourceFilterClient::FromWebContents(web_contents()); 160 return ChromeSubresourceFilterClient::FromWebContents(web_contents());
155 } 161 }
156 162
163 void RemoveURLFromBlacklist(const GURL& url) {
164 fake_safe_browsing_database_->RemoveBlacklistedUrl(url);
165 }
166
167 SubresourceFilterContentSettingsManager* settings_manager() {
168 return SubresourceFilterProfileContextFactory::GetForProfile(
169 static_cast<Profile*>(profile()))
170 ->settings_manager();
171 }
172
173 ScopedSubresourceFilterConfigurator& scoped_configuration() {
174 return scoped_configuration_;
175 }
176
157 private: 177 private:
158 base::ScopedTempDir ruleset_service_dir_; 178 base::ScopedTempDir ruleset_service_dir_;
159 TestingPrefServiceSimple pref_service_; 179 TestingPrefServiceSimple pref_service_;
160 ScopedSubresourceFilterFeatureToggle scoped_feature_toggle_; 180 ScopedSubresourceFilterFeatureToggle scoped_feature_toggle_;
161 ScopedSubresourceFilterConfigurator scoped_configuration_; 181 ScopedSubresourceFilterConfigurator scoped_configuration_;
162 182
163 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_; 183 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_;
164 184
165 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterTest); 185 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterTest);
166 }; 186 };
167 187
168 TEST_F(SubresourceFilterTest, SimpleAllowedLoad) { 188 TEST_F(SubresourceFilterTest, SimpleAllowedLoad) {
169 GURL url("https://example.test"); 189 GURL url("https://example.test");
170 SimulateNavigateAndCommit(url, main_rfh()); 190 SimulateNavigateAndCommit(url, main_rfh());
171 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh())); 191 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh()));
172 EXPECT_FALSE(client()->did_show_ui_for_navigation()); 192 EXPECT_FALSE(client()->did_show_ui_for_navigation());
173 } 193 }
174 194
175 TEST_F(SubresourceFilterTest, SimpleDisallowedLoad) { 195 TEST_F(SubresourceFilterTest, SimpleDisallowedLoad) {
176 GURL url("https://example.test"); 196 GURL url("https://example.test");
177 ConfigureAsSubresourceFilterOnlyURL(url); 197 ConfigureAsSubresourceFilterOnlyURL(url);
178 SimulateNavigateAndCommit(url, main_rfh()); 198 SimulateNavigateAndCommit(url, main_rfh());
179 EXPECT_FALSE(CreateAndNavigateDisallowedSubframe(main_rfh())); 199 EXPECT_FALSE(CreateAndNavigateDisallowedSubframe(main_rfh()));
180 EXPECT_TRUE(client()->did_show_ui_for_navigation()); 200 EXPECT_TRUE(client()->did_show_ui_for_navigation());
181 } 201 }
202
203 TEST_F(SubresourceFilterTest, DeactivateUrl_ClearsSiteMetadata) {
204 GURL url("https://a.test");
205 ConfigureAsSubresourceFilterOnlyURL(url);
206 SimulateNavigateAndCommit(url, main_rfh());
207 EXPECT_FALSE(CreateAndNavigateDisallowedSubframe(main_rfh()));
208
209 EXPECT_NE(nullptr, settings_manager()->GetSiteMetadata(url));
210
211 RemoveURLFromBlacklist(url);
212
213 // Navigate to |url| again and expect the site metadata to clear.
214 SimulateNavigateAndCommit(url, main_rfh());
215 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh()));
216
217 EXPECT_EQ(nullptr, settings_manager()->GetSiteMetadata(url));
218 }
219
220 // If the underlying configuration changes and a site only activates to DRYRUN,
221 // we should clear the metadata.
222 TEST_F(SubresourceFilterTest, ActivationToDryRun_ClearsSiteMetadata) {
223 GURL url("https://a.test");
224 ConfigureAsSubresourceFilterOnlyURL(url);
225 SimulateNavigateAndCommit(url, main_rfh());
226 EXPECT_FALSE(CreateAndNavigateDisallowedSubframe(main_rfh()));
227
228 EXPECT_NE(nullptr, settings_manager()->GetSiteMetadata(url));
229
230 // If the site later activates as DRYRUN due to e.g. a configuration change,
231 // it should also be removed from the metadata.
232 scoped_configuration().ResetConfiguration(subresource_filter::Configuration(
233 subresource_filter::ActivationLevel::DRYRUN,
234 subresource_filter::ActivationScope::ACTIVATION_LIST,
235 subresource_filter::ActivationList::SUBRESOURCE_FILTER));
236
237 // Navigate to |url| again and expect the site metadata to clear.
238 SimulateNavigateAndCommit(url, main_rfh());
239 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh()));
240
241 EXPECT_EQ(nullptr, settings_manager()->GetSiteMetadata(url));
242 }
243
244 TEST_F(SubresourceFilterTest, ExplicitWhitelisting_ShouldNotClearMetadata) {
245 GURL url("https://a.test");
246 ConfigureAsSubresourceFilterOnlyURL(url);
247 SimulateNavigateAndCommit(url, main_rfh());
248 EXPECT_FALSE(CreateAndNavigateDisallowedSubframe(main_rfh()));
249
250 // Simulate explicit whitelisting and reload.
251 settings_manager()->WhitelistSite(url);
252 SimulateNavigateAndCommit(url, main_rfh());
253 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh()));
254
255 // Should not have cleared the metadata, since the site is still on the SB
256 // blacklist.
257 EXPECT_NE(nullptr, settings_manager()->GetSiteMetadata(url));
258 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698