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

Side by Side Diff: components/subresource_filter/content/browser/subresource_filter_safe_browsing_activation_throttle_unittest.cc

Issue 2820933002: [subresource_filter] add //chrome level unit test harness (Closed)
Patch Set: remove dep Created 3 years, 8 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 "components/subresource_filter/content/browser/subresource_filter_safe_ browsing_activation_throttle.h" 5 #include "components/subresource_filter/content/browser/subresource_filter_safe_ browsing_activation_throttle.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/test/histogram_tester.h" 11 #include "base/test/histogram_tester.h"
12 #include "components/safe_browsing_db/test_database_manager.h" 12 #include "components/safe_browsing_db/test_database_manager.h"
13 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h" 13 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h"
14 #include "components/subresource_filter/content/browser/fake_safe_browsing_datab ase_manager.h"
14 #include "components/subresource_filter/content/browser/subresource_filter_clien t.h" 15 #include "components/subresource_filter/content/browser/subresource_filter_clien t.h"
15 #include "components/subresource_filter/core/browser/subresource_filter_features .h" 16 #include "components/subresource_filter/core/browser/subresource_filter_features .h"
16 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h" 17 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.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/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/navigation_handle.h" 20 #include "content/public/browser/navigation_handle.h"
20 #include "content/public/browser/web_contents_observer.h" 21 #include "content/public/browser/web_contents_observer.h"
21 #include "content/public/test/navigation_simulator.h" 22 #include "content/public/test/navigation_simulator.h"
22 #include "content/public/test/test_renderer_host.h" 23 #include "content/public/test/test_renderer_host.h"
23 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 23 matching lines...) Expand all
47 F0M1L1, // B or C, or both and D are Safe Browsing matches. 48 F0M1L1, // B or C, or both and D are Safe Browsing matches.
48 F1M0L0, // A is Safe Browsing match 49 F1M0L0, // A is Safe Browsing match
49 F1M0L1, // A and D are Safe Browsing matches. 50 F1M0L1, // A and D are Safe Browsing matches.
50 F1M1L0, // B and/or C and A are Safe Browsing matches. 51 F1M1L0, // B and/or C and A are Safe Browsing matches.
51 F1M1L1, // B and/or C and A and D are Safe Browsing matches. 52 F1M1L1, // B and/or C and A and D are Safe Browsing matches.
52 NO_REDIRECTS_HIT, // Redirect chain consists of single URL, aka no redirects 53 NO_REDIRECTS_HIT, // Redirect chain consists of single URL, aka no redirects
53 // has happened, and this URL was a Safe Browsing hit. 54 // has happened, and this URL was a Safe Browsing hit.
54 NUM_HIT_PATTERNS, 55 NUM_HIT_PATTERNS,
55 }; 56 };
56 57
57 // Database manager that allows any URL to be configured as blacklisted for
58 // testing.
59 class FakeSafeBrowsingDatabaseManager
60 : public safe_browsing::TestSafeBrowsingDatabaseManager {
61 public:
62 FakeSafeBrowsingDatabaseManager() : simulate_timeout_(false) {}
63
64 void AddBlacklistedUrl(const GURL& url,
65 safe_browsing::SBThreatType threat_type) {
66 url_to_threat_type_[url] = threat_type;
67 }
68
69 void SimulateTimeout() { simulate_timeout_ = true; }
70
71 protected:
72 ~FakeSafeBrowsingDatabaseManager() override {}
73
74 bool CheckUrlForSubresourceFilter(const GURL& url, Client* client) override {
75 if (simulate_timeout_)
76 return false;
77 if (!url_to_threat_type_.count(url))
78 return true;
79
80 content::BrowserThread::PostTask(
81 content::BrowserThread::IO, FROM_HERE,
82 base::Bind(&Client::OnCheckBrowseUrlResult, base::Unretained(client),
83 url, url_to_threat_type_[url],
84 safe_browsing::ThreatMetadata()));
85 return false;
86 }
87
88 bool CheckResourceUrl(const GURL& url, Client* client) override {
89 return true;
90 }
91
92 bool IsSupported() const override { return true; }
93 bool ChecksAreAlwaysAsync() const override { return false; }
94 bool CanCheckResourceType(
95 content::ResourceType /* resource_type */) const override {
96 return true;
97 }
98
99 safe_browsing::ThreatSource GetThreatSource() const override {
100 return safe_browsing::ThreatSource::LOCAL_PVER4;
101 }
102
103 bool CheckExtensionIDs(const std::set<std::string>& extension_ids,
104 Client* client) override {
105 return true;
106 }
107
108 private:
109 std::map<GURL, safe_browsing::SBThreatType> url_to_threat_type_;
110 bool simulate_timeout_;
111
112 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingDatabaseManager);
113 };
114
115 class MockSubresourceFilterClient 58 class MockSubresourceFilterClient
116 : public subresource_filter::SubresourceFilterClient { 59 : public subresource_filter::SubresourceFilterClient {
117 public: 60 public:
118 MockSubresourceFilterClient() {} 61 MockSubresourceFilterClient() {}
119 62
120 ~MockSubresourceFilterClient() override = default; 63 ~MockSubresourceFilterClient() override = default;
121 64
122 MOCK_METHOD1(ToggleNotificationVisibility, void(bool)); 65 MOCK_METHOD1(ToggleNotificationVisibility, void(bool));
123 MOCK_METHOD1(ShouldSuppressActivation, bool(content::NavigationHandle*)); 66 MOCK_METHOD1(ShouldSuppressActivation, bool(content::NavigationHandle*));
124 MOCK_METHOD1(WhitelistByContentSettings, void(const GURL&)); 67 MOCK_METHOD1(WhitelistByContentSettings, void(const GURL&));
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 0); 258 0);
316 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0); 259 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0);
317 } 260 }
318 261
319 // TODO(melandory): Once non-defering check in WillStart is implemented add one 262 // TODO(melandory): Once non-defering check in WillStart is implemented add one
320 // more test that destroys the Navigation along with corresponding throttles 263 // more test that destroys the Navigation along with corresponding throttles
321 // while the SB check is pending? (To be run by ASAN bots to ensure 264 // while the SB check is pending? (To be run by ASAN bots to ensure
322 // no use-after-free.) 265 // no use-after-free.)
323 266
324 } // namespace subresource_filter 267 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698