OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/safe_browsing/local_database_manager.h" |
| 6 |
5 #include <stddef.h> | 7 #include <stddef.h> |
6 | 8 |
| 9 #include <memory> |
7 #include <string> | 10 #include <string> |
8 #include <vector> | 11 #include <vector> |
9 | 12 |
10 #include "base/macros.h" | 13 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
14 #include "chrome/browser/safe_browsing/local_database_manager.h" | |
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
16 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | 17 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
17 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
18 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
19 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "testing/platform_test.h" | 22 #include "testing/platform_test.h" |
22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
23 | 24 |
24 using content::TestBrowserThreadBundle; | 25 using content::TestBrowserThreadBundle; |
(...skipping 20 matching lines...) Expand all Loading... |
45 const std::vector<SBFullHashResult>& hash_results); | 46 const std::vector<SBFullHashResult>& hash_results); |
46 | 47 |
47 TestBrowserThreadBundle thread_bundle_; | 48 TestBrowserThreadBundle thread_bundle_; |
48 }; | 49 }; |
49 | 50 |
50 bool LocalDatabaseManagerTest::RunSBHashTest( | 51 bool LocalDatabaseManagerTest::RunSBHashTest( |
51 const ListType list_type, | 52 const ListType list_type, |
52 const std::vector<SBThreatType>& expected_threats, | 53 const std::vector<SBThreatType>& expected_threats, |
53 const std::vector<std::string>& result_lists) { | 54 const std::vector<std::string>& result_lists) { |
54 const SBFullHash same_full_hash = {}; | 55 const SBFullHash same_full_hash = {}; |
55 scoped_ptr<LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck> check( | 56 std::unique_ptr<LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck> check( |
56 new LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck( | 57 new LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck( |
57 std::vector<GURL>(), std::vector<SBFullHash>(1, same_full_hash), NULL, | 58 std::vector<GURL>(), std::vector<SBFullHash>(1, same_full_hash), NULL, |
58 list_type, expected_threats)); | 59 list_type, expected_threats)); |
59 | 60 |
60 std::vector<SBFullHashResult> fake_results; | 61 std::vector<SBFullHashResult> fake_results; |
61 for (const auto& result_list : result_lists) { | 62 for (const auto& result_list : result_lists) { |
62 const SBFullHashResult full_hash_result = {same_full_hash, | 63 const SBFullHashResult full_hash_result = {same_full_hash, |
63 GetListId(result_list)}; | 64 GetListId(result_list)}; |
64 fake_results.push_back(full_hash_result); | 65 fake_results.push_back(full_hash_result); |
65 } | 66 } |
66 return RunTest(check.get(), fake_results); | 67 return RunTest(check.get(), fake_results); |
67 } | 68 } |
68 | 69 |
69 bool LocalDatabaseManagerTest::RunUrlTest( | 70 bool LocalDatabaseManagerTest::RunUrlTest( |
70 const GURL& url, ListType list_type, | 71 const GURL& url, ListType list_type, |
71 const std::vector<SBThreatType>& expected_threats, | 72 const std::vector<SBThreatType>& expected_threats, |
72 const std::vector<HostListPair>& host_list_results) { | 73 const std::vector<HostListPair>& host_list_results) { |
73 scoped_ptr<LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck> check( | 74 std::unique_ptr<LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck> check( |
74 new LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck( | 75 new LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck( |
75 std::vector<GURL>(1, url), std::vector<SBFullHash>(), NULL, | 76 std::vector<GURL>(1, url), std::vector<SBFullHash>(), NULL, list_type, |
76 list_type, expected_threats)); | 77 expected_threats)); |
77 std::vector<SBFullHashResult> full_hash_results; | 78 std::vector<SBFullHashResult> full_hash_results; |
78 for (const auto& host_list : host_list_results) { | 79 for (const auto& host_list : host_list_results) { |
79 SBFullHashResult hash_result = | 80 SBFullHashResult hash_result = |
80 {SBFullHashForString(host_list.host), GetListId(host_list.list_type)}; | 81 {SBFullHashForString(host_list.host), GetListId(host_list.list_type)}; |
81 full_hash_results.push_back(hash_result); | 82 full_hash_results.push_back(hash_result); |
82 } | 83 } |
83 return RunTest(check.get(), full_hash_results); | 84 return RunTest(check.get(), full_hash_results); |
84 } | 85 } |
85 | 86 |
86 bool LocalDatabaseManagerTest::RunTest( | 87 bool LocalDatabaseManagerTest::RunTest( |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 // Stop the service without first flushing above tasks. | 329 // Stop the service without first flushing above tasks. |
329 db_manager->StopOnIOThread(false); | 330 db_manager->StopOnIOThread(false); |
330 | 331 |
331 // Now run posted tasks, whish should include the extension check which has | 332 // Now run posted tasks, whish should include the extension check which has |
332 // been posted to the safe browsing task runner. This should not crash. | 333 // been posted to the safe browsing task runner. This should not crash. |
333 content::RunAllBlockingPoolTasksUntilIdle(); | 334 content::RunAllBlockingPoolTasksUntilIdle(); |
334 base::RunLoop().RunUntilIdle(); | 335 base::RunLoop().RunUntilIdle(); |
335 } | 336 } |
336 | 337 |
337 } // namespace safe_browsing | 338 } // namespace safe_browsing |
OLD | NEW |