Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / safe_browsing / database_manager_unittest.cc
blobaf7fda4740e97d72492e285eba10608e696fa23a
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <string>
6 #include <vector>
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/safe_browsing/database_manager.h"
11 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
12 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/platform_test.h"
15 #include "url/gurl.h"
17 using content::TestBrowserThreadBundle;
19 class SafeBrowsingDatabaseManagerTest : public PlatformTest {
20 public:
21 bool RunSBHashTest(const safe_browsing_util::ListType list_type,
22 const std::vector<SBThreatType>& expected_threats,
23 const std::string& result_list);
25 private:
26 TestBrowserThreadBundle thread_bundle_;
29 bool SafeBrowsingDatabaseManagerTest::RunSBHashTest(
30 const safe_browsing_util::ListType list_type,
31 const std::vector<SBThreatType>& expected_threats,
32 const std::string& result_list) {
33 scoped_refptr<SafeBrowsingService> sb_service_(
34 SafeBrowsingService::CreateSafeBrowsingService());
35 scoped_refptr<SafeBrowsingDatabaseManager> db_manager_(
36 new SafeBrowsingDatabaseManager(sb_service_));
37 const SBFullHash same_full_hash = {};
39 SafeBrowsingDatabaseManager::SafeBrowsingCheck* check =
40 new SafeBrowsingDatabaseManager::SafeBrowsingCheck(
41 std::vector<GURL>(),
42 std::vector<SBFullHash>(1, same_full_hash),
43 NULL,
44 list_type,
45 expected_threats);
46 db_manager_->checks_.insert(check);
48 const SBFullHashResult full_hash_result = {
49 same_full_hash,
50 safe_browsing_util::GetListId(result_list)
53 std::vector<SBFullHashResult> fake_results(1, full_hash_result);
54 bool result = db_manager_->HandleOneCheck(check, fake_results);
55 db_manager_->checks_.erase(check);
56 delete check;
57 return result;
60 TEST_F(SafeBrowsingDatabaseManagerTest, CheckCorrespondsListType) {
61 std::vector<SBThreatType> malware_threat(1,
62 SB_THREAT_TYPE_BINARY_MALWARE_URL);
63 EXPECT_FALSE(RunSBHashTest(safe_browsing_util::BINURL,
64 malware_threat,
65 safe_browsing_util::kMalwareList));
66 EXPECT_TRUE(RunSBHashTest(safe_browsing_util::BINURL,
67 malware_threat,
68 safe_browsing_util::kBinUrlList));
70 // Check for multiple threats
71 std::vector<SBThreatType> multiple_threats;
72 multiple_threats.push_back(SB_THREAT_TYPE_URL_MALWARE);
73 multiple_threats.push_back(SB_THREAT_TYPE_URL_PHISHING);
74 EXPECT_FALSE(RunSBHashTest(safe_browsing_util::MALWARE,
75 multiple_threats,
76 safe_browsing_util::kBinUrlList));
77 EXPECT_TRUE(RunSBHashTest(safe_browsing_util::MALWARE,
78 multiple_threats,
79 safe_browsing_util::kMalwareList));