OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This test creates a safebrowsing service using test safebrowsing database | 5 // This test creates a safebrowsing service using test safebrowsing database |
6 // and a test protocol manager. It is used to test logics in safebrowsing | 6 // and a test protocol manager. It is used to test logics in safebrowsing |
7 // service. | 7 // service. |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 return ContainsUrl(safe_browsing_util::kMalwareList, | 56 return ContainsUrl(safe_browsing_util::kMalwareList, |
57 safe_browsing_util::kPhishingList, | 57 safe_browsing_util::kPhishingList, |
58 url, prefix_hits, full_hits); | 58 url, prefix_hits, full_hits); |
59 } | 59 } |
60 | 60 |
61 virtual bool ContainsDownloadUrl(const GURL& url, | 61 virtual bool ContainsDownloadUrl(const GURL& url, |
62 std::vector<SBPrefix>* prefix_hits) { | 62 std::vector<SBPrefix>* prefix_hits) { |
63 std::vector<SBFullHashResult> full_hits; | 63 std::vector<SBFullHashResult> full_hits; |
64 return ContainsUrl(safe_browsing_util::kBinUrlList, | 64 return ContainsUrl(safe_browsing_util::kBinUrlList, |
65 safe_browsing_util::kBinHashList, | 65 safe_browsing_util::kBinHashList, |
66 url, prefix_hits, &full_hits); | 66 url, prefix_hits, full_hits); |
67 } | |
TVL
2011/01/26 22:13:41
did you mean to include this file?
| |
68 virtual bool ContainsDownloadHashPrefix(const SBPrefix& prefix) { | |
69 return ContainsHashPrefix(prefix); | |
67 } | 70 } |
68 | 71 |
69 virtual bool UpdateStarted(std::vector<SBListChunkRanges>* lists) { | 72 virtual bool UpdateStarted(std::vector<SBListChunkRanges>* lists) { |
70 ADD_FAILURE() << "Not implemented."; | 73 ADD_FAILURE() << "Not implemented."; |
71 return false; | 74 return false; |
72 } | 75 } |
73 virtual void InsertChunks(const std::string& list_name, | 76 virtual void InsertChunks(const std::string& list_name, |
74 const SBChunkList& chunks) { | 77 const SBChunkList& chunks) { |
75 ADD_FAILURE() << "Not implemented."; | 78 ADD_FAILURE() << "Not implemented."; |
76 } | 79 } |
(...skipping 12 matching lines...) Expand all Loading... | |
89 // Fill up the database with test URL. | 92 // Fill up the database with test URL. |
90 void AddUrl(const GURL& url, | 93 void AddUrl(const GURL& url, |
91 const std::string& list_name, | 94 const std::string& list_name, |
92 const std::vector<SBPrefix>& prefix_hits, | 95 const std::vector<SBPrefix>& prefix_hits, |
93 const std::vector<SBFullHashResult>& full_hits) { | 96 const std::vector<SBFullHashResult>& full_hits) { |
94 badurls_[url.spec()].list_name = list_name; | 97 badurls_[url.spec()].list_name = list_name; |
95 badurls_[url.spec()].prefix_hits = prefix_hits; | 98 badurls_[url.spec()].prefix_hits = prefix_hits; |
96 badurls_[url.spec()].full_hits = full_hits; | 99 badurls_[url.spec()].full_hits = full_hits; |
97 } | 100 } |
98 | 101 |
102 // Fill up the database with test hash digest. | |
103 void AddDigestPrefix(SBPrefix prefix) { | |
104 download_digest_prefix_.insert(prefix); | |
105 } | |
106 | |
99 private: | 107 private: |
100 struct Hits { | 108 struct Hits { |
101 std::string list_name; | 109 std::string list_name; |
102 std::vector<SBPrefix> prefix_hits; | 110 std::vector<SBPrefix> prefix_hits; |
103 std::vector<SBFullHashResult> full_hits; | 111 std::vector<SBFullHashResult> full_hits; |
104 }; | 112 }; |
105 | 113 |
106 bool ContainsUrl(const std::string& list_name0, | 114 bool ContainsUrl(const std::string& list_name0, |
107 const std::string& list_name1, | 115 const std::string& list_name1, |
108 const GURL& url, | 116 const GURL& url, |
109 std::vector<SBPrefix>* prefix_hits, | 117 std::vector<SBPrefix>* prefix_hits, |
110 std::vector<SBFullHashResult>* full_hits) { | 118 std::vector<SBFullHashResult>* full_hits) { |
111 base::hash_map<std::string, Hits>::const_iterator | 119 base::hash_map<std::string, Hits>::const_iterator |
112 badurls_it = badurls_.find(url.spec()); | 120 badurls_it = badurls_.find(url.spec()); |
113 | 121 |
114 if (badurls_it == badurls_.end()) | 122 if (badurls_it == badurls_.end()) |
115 return false; | 123 return false; |
116 | 124 |
117 if (badurls_it->second.list_name == list_name0 || | 125 if (badurls_it->second.list_name == list_name0 || |
118 badurls_it->second.list_name == list_name1) { | 126 badurls_it->second.list_name == list_name1) { |
119 *prefix_hits = badurls_it->second.prefix_hits; | 127 *prefix_hits = badurls_it->second.prefix_hits; |
120 *full_hits = badurls_it->second.full_hits; | 128 *full_hits = badurls_it->second.full_hits; |
121 return true; | 129 return true; |
122 } | 130 } |
123 | 131 |
124 return false; | 132 return false; |
125 } | 133 } |
126 | 134 |
127 base::hash_map<std::string, Hits> badurls_; | 135 base::hash_map<std::string, Hits> badurls_; |
136 base::prefix_set<SBPrefix> download_digest_prefix_; | |
128 }; | 137 }; |
129 | 138 |
130 // Factory that creates TestSafeBrowsingDatabase instances. | 139 // Factory that creates TestSafeBrowsingDatabase instances. |
131 class TestSafeBrowsingDatabaseFactory : public SafeBrowsingDatabaseFactory { | 140 class TestSafeBrowsingDatabaseFactory : public SafeBrowsingDatabaseFactory { |
132 public: | 141 public: |
133 TestSafeBrowsingDatabaseFactory() : db_(NULL) {} | 142 TestSafeBrowsingDatabaseFactory() : db_(NULL) {} |
134 virtual ~TestSafeBrowsingDatabaseFactory() {} | 143 virtual ~TestSafeBrowsingDatabaseFactory() {} |
135 | 144 |
136 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase( | 145 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase( |
137 bool enable_download_protection) { | 146 bool enable_download_protection) { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 chunk_id, &badbinurl_full_hash); | 393 chunk_id, &badbinurl_full_hash); |
385 SetupResponseForUrl(badbin_url, badbinurl_full_hash); | 394 SetupResponseForUrl(badbin_url, badbinurl_full_hash); |
386 | 395 |
387 client->CheckUrl(badbin_url); | 396 client->CheckUrl(badbin_url); |
388 | 397 |
389 // Now, the badbin_url is not safe since it is added to download database. | 398 // Now, the badbin_url is not safe since it is added to download database. |
390 EXPECT_EQ(SafeBrowsingService::BINARY_MALWARE, client->GetResult()); | 399 EXPECT_EQ(SafeBrowsingService::BINARY_MALWARE, client->GetResult()); |
391 } | 400 } |
392 | 401 |
393 } // namespace | 402 } // namespace |
OLD | NEW |