Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <map> | 5 #include <map> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/metrics/subprocess_metrics_provider.h" | 20 #include "chrome/browser/metrics/subprocess_metrics_provider.h" |
| 21 #include "chrome/browser/page_load_metrics/observers/subresource_filter_metrics_ observer.h" | 21 #include "chrome/browser/page_load_metrics/observers/subresource_filter_metrics_ observer.h" |
| 22 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" | 22 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" |
| 23 #include "chrome/browser/safe_browsing/v4_test_utils.h" | |
| 23 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h" | 24 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h" |
| 24 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_commands.h" | 26 #include "chrome/browser/ui/browser_commands.h" |
| 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 27 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 29 #include "chrome/test/base/in_process_browser_test.h" | 30 #include "chrome/test/base/in_process_browser_test.h" |
| 30 #include "chrome/test/base/ui_test_utils.h" | 31 #include "chrome/test/base/ui_test_utils.h" |
| 31 #include "components/safe_browsing_db/test_database_manager.h" | 32 #include "components/safe_browsing_db/test_database_manager.h" |
| 32 #include "components/safe_browsing_db/util.h" | 33 #include "components/safe_browsing_db/util.h" |
| 34 #include "components/safe_browsing_db/v4_database.h" | |
| 33 #include "components/security_interstitials/content/unsafe_resource.h" | 35 #include "components/security_interstitials/content/unsafe_resource.h" |
| 34 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h" | 36 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h" |
| 35 #include "components/subresource_filter/core/browser/subresource_filter_features .h" | 37 #include "components/subresource_filter/core/browser/subresource_filter_features .h" |
| 36 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h" | 38 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h" |
| 37 #include "components/subresource_filter/core/common/activation_level.h" | 39 #include "components/subresource_filter/core/common/activation_level.h" |
| 38 #include "components/subresource_filter/core/common/scoped_timers.h" | 40 #include "components/subresource_filter/core/common/scoped_timers.h" |
| 39 #include "components/subresource_filter/core/common/test_ruleset_utils.h" | 41 #include "components/subresource_filter/core/common/test_ruleset_utils.h" |
| 40 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 41 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
| 42 #include "content/public/browser/notification_types.h" | 44 #include "content/public/browser/notification_types.h" |
| 43 #include "content/public/browser/render_frame_host.h" | 45 #include "content/public/browser/render_frame_host.h" |
| 44 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
| 45 #include "content/public/common/content_switches.h" | 47 #include "content/public/common/content_switches.h" |
| 46 #include "content/public/test/browser_test_utils.h" | 48 #include "content/public/test/browser_test_utils.h" |
| 47 #include "content/public/test/test_navigation_observer.h" | 49 #include "content/public/test/test_navigation_observer.h" |
| 48 #include "content/public/test/test_utils.h" | 50 #include "content/public/test/test_utils.h" |
| 49 #include "net/dns/mock_host_resolver.h" | 51 #include "net/dns/mock_host_resolver.h" |
| 50 #include "net/test/embedded_test_server/embedded_test_server.h" | 52 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 51 #include "net/test/spawned_test_server/spawned_test_server.h" | 53 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 52 #include "net/test/test_data_directory.h" | 54 #include "net/test/test_data_directory.h" |
| 53 #include "testing/gmock/include/gmock/gmock.h" | 55 #include "testing/gmock/include/gmock/gmock.h" |
| 54 #include "testing/gtest/include/gtest/gtest.h" | 56 #include "testing/gtest/include/gtest/gtest.h" |
| 55 | 57 |
| 56 namespace { | 58 namespace { |
| 57 | 59 |
| 58 // The path to a multi-frame document used for tests. | 60 // The path to a multi-frame document used for tests. |
| 59 static constexpr const char kTestFrameSetPath[] = | 61 static constexpr const char kTestFrameSetPath[] = |
| 60 "subresource_filter/frame_set.html"; | 62 "/subresource_filter/frame_set.html"; |
| 61 | 63 |
| 62 // Names of DocumentLoad histograms. | 64 // Names of DocumentLoad histograms. |
| 63 constexpr const char kDocumentLoadActivationLevel[] = | 65 constexpr const char kDocumentLoadActivationLevel[] = |
| 64 "SubresourceFilter.DocumentLoad.ActivationState"; | 66 "SubresourceFilter.DocumentLoad.ActivationState"; |
| 65 constexpr const char kSubresourceLoadsTotal[] = | 67 constexpr const char kSubresourceLoadsTotal[] = |
| 66 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Total"; | 68 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Total"; |
| 67 constexpr const char kSubresourceLoadsEvaluated[] = | 69 constexpr const char kSubresourceLoadsEvaluated[] = |
| 68 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Evaluated"; | 70 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Evaluated"; |
| 69 constexpr const char kSubresourceLoadsMatchedRules[] = | 71 constexpr const char kSubresourceLoadsMatchedRules[] = |
| 70 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.MatchedRules"; | 72 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.MatchedRules"; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 91 "SubresourceFilter.PageLoad.SubresourceEvaluation.TotalCPUDuration"; | 93 "SubresourceFilter.PageLoad.SubresourceEvaluation.TotalCPUDuration"; |
| 92 constexpr const char kEvaluationTotalWallDurationForDocument[] = | 94 constexpr const char kEvaluationTotalWallDurationForDocument[] = |
| 93 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalWallDuration"; | 95 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalWallDuration"; |
| 94 constexpr const char kEvaluationTotalCPUDurationForDocument[] = | 96 constexpr const char kEvaluationTotalCPUDurationForDocument[] = |
| 95 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalCPUDuration"; | 97 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalCPUDuration"; |
| 96 constexpr const char kEvaluationWallDuration[] = | 98 constexpr const char kEvaluationWallDuration[] = |
| 97 "SubresourceFilter.SubresourceLoad.Evaluation.WallDuration"; | 99 "SubresourceFilter.SubresourceLoad.Evaluation.WallDuration"; |
| 98 constexpr const char kEvaluationCPUDuration[] = | 100 constexpr const char kEvaluationCPUDuration[] = |
| 99 "SubresourceFilter.SubresourceLoad.Evaluation.CPUDuration"; | 101 "SubresourceFilter.SubresourceLoad.Evaluation.CPUDuration"; |
| 100 | 102 |
| 103 #if defined(GOOGLE_CHROME_BUILD) | |
| 104 // Names of navigation chain patterns diagram. | |
|
engedy
2017/03/10 14:39:32
nit: ... histograms.
melandory
2017/03/15 13:41:35
Done.
| |
| 105 const char kMatchesPatternHistogramName[] = | |
| 106 "SubresourceFilter.PageLoad.RedirectChainMatchPattern"; | |
| 107 const char kNavigationChainSize[] = | |
| 108 "SubresourceFilter.PageLoad.RedirectChainLength"; | |
| 109 const char kSubresourceFilterOnlySuffix[] = ".SubresourceFilterOnly"; | |
| 110 #endif | |
| 111 | |
| 101 // Other histograms. | 112 // Other histograms. |
| 102 const char kSubresourceFilterPromptHistogram[] = | 113 const char kSubresourceFilterPromptHistogram[] = |
| 103 "SubresourceFilter.Prompt.NumVisibility"; | 114 "SubresourceFilter.Prompt.NumVisibility"; |
| 104 | 115 |
| 105 // Database manager that allows any URL to be configured as blacklisted for | 116 // Human readable representation of expected redirect chain match patterns. |
| 106 // testing. | 117 // The explanations for the buckets given for the following redirect chain: |
| 107 class FakeSafeBrowsingDatabaseManager | 118 // A->B->C->D, where A is initial URL and D is a final URL. |
| 108 : public safe_browsing::TestSafeBrowsingDatabaseManager { | 119 enum RedirectChainMatchPattern { |
| 109 public: | 120 EMPTY, // No histograms were recorded. |
| 110 FakeSafeBrowsingDatabaseManager() {} | 121 F0M0L1, // D is a Safe Browsing match. |
| 111 | 122 F0M1L0, // B or C, or both are Safe Browsing matches. |
| 112 void AddBlacklistedURL(const GURL& url, | 123 F0M1L1, // B or C, or both and D are Safe Browsing matches. |
| 113 safe_browsing::SBThreatType threat_type) { | 124 F1M0L0, // A is Safe Browsing match |
| 114 url_to_threat_type_[url] = threat_type; | 125 F1M0L1, // A and D are Safe Browsing matches. |
| 115 } | 126 F1M1L0, // B and/or C and A are Safe Browsing matches. |
| 116 | 127 F1M1L1, // B and/or C and A and D are Safe Browsing matches. |
| 117 protected: | 128 NO_REDIRECTS_HIT, // Redirect chain consists of single URL, aka no redirects |
| 118 ~FakeSafeBrowsingDatabaseManager() override {} | 129 // has happened, and this URL was a Safe Browsing hit. |
| 119 | 130 NUM_HIT_PATTERNS, |
| 120 bool CheckBrowseUrl(const GURL& url, Client* client) override { | |
| 121 if (!url_to_threat_type_.count(url)) | |
| 122 return true; | |
| 123 | |
| 124 content::BrowserThread::PostTask( | |
| 125 content::BrowserThread::IO, FROM_HERE, | |
| 126 base::Bind(&Client::OnCheckBrowseUrlResult, base::Unretained(client), | |
| 127 url, url_to_threat_type_[url], | |
| 128 safe_browsing::ThreatMetadata())); | |
| 129 return false; | |
| 130 } | |
| 131 | |
| 132 bool CheckResourceUrl(const GURL& url, Client* client) override { | |
| 133 return true; | |
| 134 } | |
| 135 | |
| 136 bool IsSupported() const override { return true; } | |
| 137 bool ChecksAreAlwaysAsync() const override { return false; } | |
| 138 bool CanCheckResourceType( | |
| 139 content::ResourceType /* resource_type */) const override { | |
| 140 return true; | |
| 141 } | |
| 142 | |
| 143 safe_browsing::ThreatSource GetThreatSource() const override { | |
| 144 return safe_browsing::ThreatSource::LOCAL_PVER4; | |
| 145 } | |
| 146 | |
| 147 bool CheckExtensionIDs(const std::set<std::string>& extension_ids, | |
| 148 Client* client) override { | |
| 149 return true; | |
| 150 } | |
| 151 | |
| 152 private: | |
| 153 std::map<GURL, safe_browsing::SBThreatType> url_to_threat_type_; | |
| 154 | |
| 155 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingDatabaseManager); | |
| 156 }; | 131 }; |
| 157 | 132 |
| 158 // UI manager that never actually shows any interstitials, but emulates as if | 133 // UI manager that never actually shows any interstitials, but emulates as if |
| 159 // the user chose to proceed through them. | 134 // the user chose to proceed through them. |
| 160 class FakeSafeBrowsingUIManager | 135 class FakeSafeBrowsingUIManager |
| 161 : public safe_browsing::TestSafeBrowsingUIManager { | 136 : public safe_browsing::TestSafeBrowsingUIManager { |
| 162 public: | 137 public: |
| 163 FakeSafeBrowsingUIManager() {} | 138 FakeSafeBrowsingUIManager() {} |
| 164 | 139 |
| 165 protected: | 140 protected: |
| 166 ~FakeSafeBrowsingUIManager() override {} | 141 ~FakeSafeBrowsingUIManager() override {} |
| 167 | 142 |
| 168 void DisplayBlockingPage(const UnsafeResource& resource) override { | 143 void DisplayBlockingPage(const UnsafeResource& resource) override { |
| 169 resource.callback_thread->PostTask( | 144 resource.callback_thread->PostTask( |
| 170 FROM_HERE, base::Bind(resource.callback, true /* proceed */)); | 145 FROM_HERE, base::Bind(resource.callback, true /* proceed */)); |
| 171 } | 146 } |
| 172 | 147 |
| 173 private: | 148 private: |
| 174 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingUIManager); | 149 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingUIManager); |
| 175 }; | 150 }; |
| 176 | 151 |
| 177 GURL GetURLWithFragment(const GURL& url, base::StringPiece fragment) { | 152 GURL GetURLWithFragment(const GURL& url, base::StringPiece fragment) { |
| 178 GURL::Replacements replacements; | 153 GURL::Replacements replacements; |
| 179 replacements.SetRefStr(fragment); | 154 replacements.SetRefStr(fragment); |
| 180 return url.ReplaceComponents(replacements); | 155 return url.ReplaceComponents(replacements); |
| 181 } | 156 } |
| 182 | 157 |
| 183 GURL GetURLWithQuery(const GURL& url, base::StringPiece query) { | |
| 184 GURL::Replacements replacements; | |
| 185 replacements.SetQueryStr(query); | |
| 186 return url.ReplaceComponents(replacements); | |
| 187 } | |
| 188 | |
| 189 } // namespace | 158 } // namespace |
| 190 | 159 |
| 191 namespace subresource_filter { | 160 namespace subresource_filter { |
| 192 | 161 |
| 193 using subresource_filter::testing::ScopedSubresourceFilterFeatureToggle; | 162 using subresource_filter::testing::ScopedSubresourceFilterFeatureToggle; |
| 194 using subresource_filter::testing::TestRulesetPublisher; | 163 using subresource_filter::testing::TestRulesetPublisher; |
| 195 using subresource_filter::testing::TestRulesetCreator; | 164 using subresource_filter::testing::TestRulesetCreator; |
| 196 using subresource_filter::testing::TestRulesetPair; | 165 using subresource_filter::testing::TestRulesetPair; |
| 197 using ActivationDecision = | 166 using ActivationDecision = |
| 198 ContentSubresourceFilterDriverFactory::ActivationDecision; | 167 ContentSubresourceFilterDriverFactory::ActivationDecision; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 222 // called after ChromeBrowserMainParts::PreBrowserStart(), which instantiates | 191 // called after ChromeBrowserMainParts::PreBrowserStart(), which instantiates |
| 223 // the RulesetService. | 192 // the RulesetService. |
| 224 // | 193 // |
| 225 // On the other hand, setting up field trials in this method would be too | 194 // On the other hand, setting up field trials in this method would be too |
| 226 // early, as it is called before BrowserMain, which expects no FieldTrialList | 195 // early, as it is called before BrowserMain, which expects no FieldTrialList |
| 227 // singleton to exist. There are no other hooks we could use either. | 196 // singleton to exist. There are no other hooks we could use either. |
| 228 // | 197 // |
| 229 // As a workaround, enable the feature here, then enable the feature once | 198 // As a workaround, enable the feature here, then enable the feature once |
| 230 // again + set up the field trials later. | 199 // again + set up the field trials later. |
| 231 void SetUpCommandLine(base::CommandLine* command_line) override { | 200 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 232 command_line->AppendSwitchASCII(switches::kEnableFeatures, | 201 command_line->AppendSwitchASCII( |
| 233 kSafeBrowsingSubresourceFilter.name); | 202 switches::kEnableFeatures, |
| 203 std::string(kSafeBrowsingSubresourceFilter.name) + | |
|
engedy
2017/03/10 14:39:32
nit: Let's make this nicer by either appending two
melandory
2017/03/15 13:41:36
Done.
| |
| 204 ", SafeBrowsingV4OnlyEnabled"); | |
| 234 } | 205 } |
| 235 | 206 |
| 236 void SetUpInProcessBrowserTestFixture() override { | 207 void SetUp() override { |
| 237 fake_safe_browsing_database_ = new FakeSafeBrowsingDatabaseManager(); | 208 sb_factory_ = |
| 238 test_safe_browsing_factory_.SetTestDatabaseManager( | 209 base::MakeUnique<safe_browsing::TestSafeBrowsingServiceFactory>( |
| 239 fake_safe_browsing_database_.get()); | 210 safe_browsing::V4FeatureList::V4UsageStatus::V4_ONLY); |
| 240 test_safe_browsing_factory_.SetTestUIManager(new FakeSafeBrowsingUIManager); | 211 sb_factory_->SetTestUIManager(new FakeSafeBrowsingUIManager()); |
| 241 safe_browsing::SafeBrowsingService::RegisterFactory( | 212 safe_browsing::SafeBrowsingService::RegisterFactory(sb_factory_.get()); |
| 242 &test_safe_browsing_factory_); | 213 |
| 214 store_factory_ = new safe_browsing::TestV4StoreFactory(); | |
|
engedy
2017/03/10 14:39:32
nit: Not used outside of this function.
melandory
2017/03/15 13:41:35
Done.
| |
| 215 safe_browsing::V4Database::RegisterStoreFactoryForTest( | |
| 216 base::WrapUnique(store_factory_)); | |
| 217 | |
| 218 v4_db_factory_ = new safe_browsing::TestV4DatabaseFactory(); | |
| 219 safe_browsing::V4Database::RegisterDatabaseFactoryForTest( | |
| 220 base::WrapUnique(v4_db_factory_)); | |
| 221 | |
| 222 v4_get_hash_factory_ = | |
| 223 new safe_browsing::TestV4GetHashProtocolManagerFactory(); | |
| 224 safe_browsing::V4GetHashProtocolManager::RegisterFactory( | |
| 225 base::WrapUnique(v4_get_hash_factory_)); | |
| 226 InProcessBrowserTest::SetUp(); | |
| 227 } | |
| 228 | |
| 229 void TearDown() override { | |
| 230 InProcessBrowserTest::TearDown(); | |
| 231 // Unregister test factories after InProcessBrowserTest::TearDown | |
| 232 // (which destructs SafeBrowsingService). | |
| 233 safe_browsing::V4GetHashProtocolManager::RegisterFactory(nullptr); | |
| 234 safe_browsing::V4Database::RegisterDatabaseFactoryForTest(nullptr); | |
| 235 safe_browsing::V4Database::RegisterStoreFactoryForTest(nullptr); | |
| 236 safe_browsing::SafeBrowsingService::RegisterFactory(nullptr); | |
| 243 } | 237 } |
| 244 | 238 |
| 245 void SetUpOnMainThread() override { | 239 void SetUpOnMainThread() override { |
| 246 scoped_feature_toggle_.reset(new ScopedSubresourceFilterFeatureToggle( | 240 scoped_feature_toggle_.reset(new ScopedSubresourceFilterFeatureToggle( |
| 247 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 241 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 248 kActivationScopeActivationList, kActivationListPhishingInterstitial, | 242 kActivationScopeActivationList, kActivationListPhishingInterstitial, |
| 249 measure_performance_ ? "1" : "0", "" /* suppress_notifications */, | 243 measure_performance_ ? "1" : "0", "" /* suppress_notifications */, |
| 250 whitelist_site_on_reload_ ? "true" : "false")); | 244 whitelist_site_on_reload_ ? "true" : "false")); |
| 251 | 245 |
| 252 base::FilePath test_data_dir; | 246 base::FilePath test_data_dir; |
| 253 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 247 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 254 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | 248 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
| 255 host_resolver()->AddSimulatedFailure("host-with-dns-lookup-failure"); | 249 host_resolver()->AddSimulatedFailure("host-with-dns-lookup-failure"); |
| 256 host_resolver()->AddRule("*", "127.0.0.1"); | 250 host_resolver()->AddRule("*", "127.0.0.1"); |
| 257 content::SetupCrossSiteRedirector(embedded_test_server()); | 251 content::SetupCrossSiteRedirector(embedded_test_server()); |
| 258 ASSERT_TRUE(embedded_test_server()->Start()); | 252 ASSERT_TRUE(embedded_test_server()->Start()); |
| 259 } | 253 } |
| 260 | 254 |
| 261 GURL GetTestUrl(const std::string& relative_url) { | 255 GURL GetTestUrl(const std::string& relative_url) { |
| 262 return embedded_test_server()->base_url().Resolve(relative_url); | 256 return embedded_test_server()->base_url().Resolve(relative_url); |
| 263 } | 257 } |
| 264 | 258 |
| 259 void MarkUrlForListIdUnexpired( | |
|
engedy
2017/03/10 14:39:32
nit: Add comment for what `unexpired` means, or na
melandory
2017/03/15 13:41:36
Done.
| |
| 260 const GURL& bad_url, | |
| 261 const safe_browsing::ListIdentifier& list_id, | |
| 262 safe_browsing::ThreatPatternType threat_pattern_type) { | |
| 263 safe_browsing::FullHashInfo full_hash_info = | |
| 264 GetFullHashInfoWithMetadata(bad_url, list_id, threat_pattern_type); | |
| 265 v4_db_factory_->MarkPrefixAsBad(list_id, full_hash_info.full_hash); | |
| 266 v4_get_hash_factory_->AddToFullHashCache(full_hash_info); | |
| 267 } | |
| 268 | |
| 265 void ConfigureAsPhishingURL(const GURL& url) { | 269 void ConfigureAsPhishingURL(const GURL& url) { |
| 266 fake_safe_browsing_database_->AddBlacklistedURL( | 270 MarkUrlForListIdUnexpired(url, safe_browsing::GetUrlSocEngId(), |
| 267 url, safe_browsing::SB_THREAT_TYPE_URL_PHISHING); | 271 safe_browsing::ThreatPatternType::NONE); |
| 272 } | |
| 273 | |
| 274 void ConfigureAsSubresourceFilterOnlyURL(const GURL& url) { | |
| 275 MarkUrlForListIdUnexpired(url, safe_browsing::GetUrlSubresourceFilterId(), | |
| 276 safe_browsing::ThreatPatternType::NONE); | |
| 268 } | 277 } |
| 269 | 278 |
| 270 content::WebContents* web_contents() { | 279 content::WebContents* web_contents() { |
| 271 return browser()->tab_strip_model()->GetActiveWebContents(); | 280 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 272 } | 281 } |
| 273 | 282 |
| 274 content::RenderFrameHost* FindFrameByName(const std::string& name) { | 283 content::RenderFrameHost* FindFrameByName(const std::string& name) { |
| 275 for (content::RenderFrameHost* frame : web_contents()->GetAllFrames()) { | 284 for (content::RenderFrameHost* frame : web_contents()->GetAllFrames()) { |
| 276 if (frame->GetFrameName() == name) | 285 if (frame->GetFrameName() == name) |
| 277 return frame; | 286 return frame; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 | 342 |
| 334 void SetRulesetWithRules(const std::vector<proto::UrlRule>& rules) { | 343 void SetRulesetWithRules(const std::vector<proto::UrlRule>& rules) { |
| 335 TestRulesetPair test_ruleset_pair; | 344 TestRulesetPair test_ruleset_pair; |
| 336 ruleset_creator_.CreateRulesetWithRules(rules, &test_ruleset_pair); | 345 ruleset_creator_.CreateRulesetWithRules(rules, &test_ruleset_pair); |
| 337 ASSERT_NO_FATAL_FAILURE( | 346 ASSERT_NO_FATAL_FAILURE( |
| 338 test_ruleset_publisher_.SetRuleset(test_ruleset_pair.unindexed)); | 347 test_ruleset_publisher_.SetRuleset(test_ruleset_pair.unindexed)); |
| 339 } | 348 } |
| 340 | 349 |
| 341 private: | 350 private: |
| 342 TestRulesetCreator ruleset_creator_; | 351 TestRulesetCreator ruleset_creator_; |
| 343 safe_browsing::TestSafeBrowsingServiceFactory test_safe_browsing_factory_; | |
| 344 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_; | |
| 345 | 352 |
| 346 std::unique_ptr<ScopedSubresourceFilterFeatureToggle> scoped_feature_toggle_; | 353 std::unique_ptr<ScopedSubresourceFilterFeatureToggle> scoped_feature_toggle_; |
| 347 TestRulesetPublisher test_ruleset_publisher_; | 354 TestRulesetPublisher test_ruleset_publisher_; |
| 348 const bool measure_performance_; | 355 const bool measure_performance_; |
| 349 const bool whitelist_site_on_reload_; | 356 const bool whitelist_site_on_reload_; |
| 350 | 357 |
| 358 std::unique_ptr<safe_browsing::TestSafeBrowsingServiceFactory> sb_factory_; | |
| 359 // Owned by the V4Database. | |
| 360 safe_browsing::TestV4DatabaseFactory* v4_db_factory_; | |
| 361 // Owned by the V4GetHashProtocolManager. | |
| 362 safe_browsing::TestV4GetHashProtocolManagerFactory* v4_get_hash_factory_; | |
| 363 // Owned by the V4Database. | |
| 364 safe_browsing::TestV4StoreFactory* store_factory_; | |
| 365 | |
| 351 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterBrowserTestImpl); | 366 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterBrowserTestImpl); |
| 352 }; | 367 }; |
| 353 | 368 |
| 354 class SubresourceFilterBrowserTest : public SubresourceFilterBrowserTestImpl { | 369 class SubresourceFilterBrowserTest : public SubresourceFilterBrowserTestImpl { |
| 355 public: | 370 public: |
| 356 SubresourceFilterBrowserTest() | 371 SubresourceFilterBrowserTest() |
| 357 : SubresourceFilterBrowserTestImpl(false, false) {} | 372 : SubresourceFilterBrowserTestImpl(false, false) {} |
| 358 }; | 373 }; |
| 359 | 374 |
| 360 // TODO(pkalinnikov): It should be possible to have only one fixture, i.e., | 375 // TODO(pkalinnikov): It should be possible to have only one fixture, i.e., |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 const std::vector<const char*> kSubframeNames{"one", "two", "three"}; | 487 const std::vector<const char*> kSubframeNames{"one", "two", "three"}; |
| 473 const std::vector<bool> kExpectScriptInFrameToLoad{false, true, false}; | 488 const std::vector<bool> kExpectScriptInFrameToLoad{false, true, false}; |
| 474 ASSERT_NO_FATAL_FAILURE(ExpectParsedScriptElementLoadedStatusInFrames( | 489 ASSERT_NO_FATAL_FAILURE(ExpectParsedScriptElementLoadedStatusInFrames( |
| 475 kSubframeNames, kExpectScriptInFrameToLoad)); | 490 kSubframeNames, kExpectScriptInFrameToLoad)); |
| 476 | 491 |
| 477 tester.ExpectBucketCount(kSubresourceFilterPromptHistogram, true, 1); | 492 tester.ExpectBucketCount(kSubresourceFilterPromptHistogram, true, 1); |
| 478 } | 493 } |
| 479 | 494 |
| 480 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, | 495 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, |
| 481 HistoryNavigationActivation) { | 496 HistoryNavigationActivation) { |
| 482 GURL url_without_activation(GetTestUrl(kTestFrameSetPath)); | 497 GURL url_with_activation(GetTestUrl(kTestFrameSetPath)); |
| 483 GURL url_with_activation( | 498 GURL url_without_activation( |
| 484 GetURLWithQuery(url_without_activation, "activation")); | 499 embedded_test_server()->GetURL("a.com", kTestFrameSetPath)); |
| 485 ConfigureAsPhishingURL(url_with_activation); | 500 ConfigureAsPhishingURL(url_with_activation); |
| 486 ASSERT_NO_FATAL_FAILURE( | 501 ASSERT_NO_FATAL_FAILURE( |
| 487 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); | 502 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); |
| 488 | 503 |
| 489 const std::vector<const char*> kSubframeNames{"one", "two", "three"}; | 504 const std::vector<const char*> kSubframeNames{"one", "two", "three"}; |
| 490 const std::vector<bool> kExpectScriptInFrameToLoadWithoutActivation{ | 505 const std::vector<bool> kExpectScriptInFrameToLoadWithoutActivation{ |
| 491 true, true, true}; | 506 true, true, true}; |
| 492 const std::vector<bool> kExpectScriptInFrameToLoadWithActivation{false, true, | 507 const std::vector<bool> kExpectScriptInFrameToLoadWithActivation{false, true, |
| 493 false}; | 508 false}; |
| 494 | 509 |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 989 internal::kHistogramSubresourceFilterActivationDecision, | 1004 internal::kHistogramSubresourceFilterActivationDecision, |
| 990 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); | 1005 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); |
| 991 | 1006 |
| 992 tester.ExpectTotalCount( | 1007 tester.ExpectTotalCount( |
| 993 internal::kHistogramSubresourceFilterActivationDecisionReload, 1); | 1008 internal::kHistogramSubresourceFilterActivationDecisionReload, 1); |
| 994 tester.ExpectBucketCount( | 1009 tester.ExpectBucketCount( |
| 995 internal::kHistogramSubresourceFilterActivationDecisionReload, | 1010 internal::kHistogramSubresourceFilterActivationDecisionReload, |
| 996 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); | 1011 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); |
| 997 } | 1012 } |
| 998 | 1013 |
| 1014 #if defined(GOOGLE_CHROME_BUILD) | |
| 1015 // This test is only enabled when GOOGLE_CHROME_BUILD is true because the store | |
| 1016 // that this test uses is only populated on GOOGLE_CHROME_BUILD builds. | |
| 1017 IN_PROC_BROWSER_TEST_F( | |
| 1018 SubresourceFilterBrowserTest, | |
| 1019 ExpectRedirectPatternHistogramsAreRecordedForSubresourceFilterOnlyMatch) { | |
| 1020 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix( | |
| 1021 "suffix-that-does-not-match-anything")); | |
| 1022 | |
| 1023 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); | |
| 1024 ConfigureAsSubresourceFilterOnlyURL(url); | |
| 1025 | |
| 1026 base::HistogramTester tester; | |
| 1027 ui_test_utils::NavigateToURL(browser(), url); | |
| 1028 | |
| 1029 EXPECT_THAT(tester.GetAllSamples(std::string(kMatchesPatternHistogramName) + | |
| 1030 std::string(kSubresourceFilterOnlySuffix)), | |
| 1031 ::testing::ElementsAre(base::Bucket(NO_REDIRECTS_HIT, 1))); | |
| 1032 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + | |
| 1033 std::string(kSubresourceFilterOnlySuffix)), | |
| 1034 ::testing::ElementsAre(base::Bucket(1, 1))); | |
| 1035 } | |
| 1036 | |
| 1037 IN_PROC_BROWSER_TEST_F( | |
| 1038 SubresourceFilterBrowserTest, | |
| 1039 ExpectRedirectPatternHistogramsAreRecordedForSubresourceFilterOnlyRedirectMa tch) { | |
| 1040 ASSERT_NO_FATAL_FAILURE( | |
| 1041 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); | |
| 1042 const std::string initial_host("a.com"); | |
| 1043 const std::string redirected_host("b.com"); | |
| 1044 | |
| 1045 GURL redirect_url(embedded_test_server()->GetURL( | |
| 1046 redirected_host, "/subresource_filter/frame_with_included_script.html")); | |
| 1047 GURL url(embedded_test_server()->GetURL( | |
| 1048 initial_host, "/server-redirect?" + redirect_url.spec())); | |
| 1049 | |
| 1050 ConfigureAsSubresourceFilterOnlyURL(url.GetOrigin()); | |
| 1051 base::HistogramTester tester; | |
| 1052 ui_test_utils::NavigateToURL(browser(), url); | |
| 1053 EXPECT_THAT(tester.GetAllSamples(std::string(kMatchesPatternHistogramName) + | |
| 1054 std::string(kSubresourceFilterOnlySuffix)), | |
| 1055 ::testing::IsEmpty()); | |
| 1056 | |
| 1057 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + | |
| 1058 std::string(kSubresourceFilterOnlySuffix)), | |
| 1059 ::testing::IsEmpty()); | |
| 1060 } | |
| 1061 #endif | |
| 1062 | |
| 999 } // namespace subresource_filter | 1063 } // namespace subresource_filter |
| OLD | NEW |