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

Side by Side Diff: chrome/browser/download/download_safe_browsing_client_unittest.cc

Issue 7134017: Make safe browsing work in a multi-profile environment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "chrome/browser/download/download_safe_browsing_client.h" 6 #include "chrome/browser/download/download_safe_browsing_client.h"
7 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 7 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
8 #include "content/browser/browser_thread.h" 8 #include "content/browser/browser_thread.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace { 12 namespace {
13 13
14 const char* kUrl1 = "http://127.0.0.1/"; 14 const char* kUrl1 = "http://127.0.0.1/";
15 const char* kUrl2 = "http://127.0.0.1/two"; 15 const char* kUrl2 = "http://127.0.0.1/two";
16 const char* kUrl3 = "http://127.0.0.1/three"; 16 const char* kUrl3 = "http://127.0.0.1/three";
17 const char* kRefUrl = "http://127.0.0.1/referrer"; 17 const char* kRefUrl = "http://127.0.0.1/referrer";
18 18
19 class MockSafeBrowsingService : public SafeBrowsingService { 19 class MockSafeBrowsingService : public SafeBrowsingService {
20 public: 20 public:
21 MockSafeBrowsingService() {} 21 MockSafeBrowsingService() {}
22 virtual ~MockSafeBrowsingService() {} 22 virtual ~MockSafeBrowsingService() {}
23 23
24 MOCK_METHOD6(ReportSafeBrowsingHit, 24 MOCK_METHOD7(ReportSafeBrowsingHit,
25 void(const GURL&, const GURL&, const GURL&, bool, UrlCheckResult, 25 void(const GURL&, const GURL&, const GURL&, bool, UrlCheckResult,
26 const std::string&)); 26 const std::string&, bool));
27 27
28 private: 28 private:
29 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingService); 29 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingService);
30 }; 30 };
31 31
32 } // namespace 32 } // namespace
33 33
34 class DownloadSBClientTest : public testing::Test { 34 class DownloadSBClientTest : public testing::Test {
35 public: 35 public:
36 DownloadSBClientTest() : 36 DownloadSBClientTest() :
37 ui_thread_(BrowserThread::UI, &loop_) { 37 ui_thread_(BrowserThread::UI, &loop_) {
38 } 38 }
39 39
40 private: 40 private:
41 MessageLoop loop_; 41 MessageLoop loop_;
42 42
43 // UI thread to satisfy debug checks in DownloadSBClient. 43 // UI thread to satisfy debug checks in DownloadSBClient.
44 BrowserThread ui_thread_; 44 BrowserThread ui_thread_;
45 }; 45 };
46 46
47 TEST_F(DownloadSBClientTest, UrlHit) { 47 TEST_F(DownloadSBClientTest, UrlHit) {
48 std::string expected_post = 48 std::string expected_post =
49 std::string(kUrl1) + "\n" + kUrl2 + "\n" + kUrl3 + "\n"; 49 std::string(kUrl1) + "\n" + kUrl2 + "\n" + kUrl3 + "\n";
50 scoped_refptr<MockSafeBrowsingService> sb_service( 50 scoped_refptr<MockSafeBrowsingService> sb_service(
51 new MockSafeBrowsingService); 51 new MockSafeBrowsingService);
52 EXPECT_CALL(*sb_service.get(), 52 EXPECT_CALL(*sb_service.get(),
53 ReportSafeBrowsingHit(GURL(kUrl3), GURL(kUrl1), GURL(kRefUrl), true, 53 ReportSafeBrowsingHit(GURL(kUrl3), GURL(kUrl1), GURL(kRefUrl), true,
54 SafeBrowsingService::BINARY_MALWARE_URL, 54 SafeBrowsingService::BINARY_MALWARE_URL,
55 expected_post)); 55 expected_post, true));
56 std::vector<GURL> url_chain; 56 std::vector<GURL> url_chain;
57 url_chain.push_back(GURL(kUrl1)); 57 url_chain.push_back(GURL(kUrl1));
58 url_chain.push_back(GURL(kUrl2)); 58 url_chain.push_back(GURL(kUrl2));
59 url_chain.push_back(GURL(kUrl3)); 59 url_chain.push_back(GURL(kUrl3));
60 60
61 scoped_refptr<DownloadSBClient> client( 61 scoped_refptr<DownloadSBClient> client(
62 new DownloadSBClient(1, url_chain, GURL(kRefUrl))); 62 new DownloadSBClient(1, url_chain, GURL(kRefUrl), true));
63 client->SetSBService(sb_service.get()); 63 client->SetSBService(sb_service.get());
64 64
65 client->ReportMalware(SafeBrowsingService::BINARY_MALWARE_URL, ""); 65 client->ReportMalware(SafeBrowsingService::BINARY_MALWARE_URL, "");
66 } 66 }
67 67
68 TEST_F(DownloadSBClientTest, DigestHit) { 68 TEST_F(DownloadSBClientTest, DigestHit) {
69 std::string hash_data = "\xDE\xAD\xBE\xEF"; 69 std::string hash_data = "\xDE\xAD\xBE\xEF";
70 std::string hash_string = "DEADBEEF"; 70 std::string hash_string = "DEADBEEF";
71 std::string expected_post = 71 std::string expected_post =
72 hash_string + "\n" + kUrl1 + "\n" + kUrl2 + "\n" + kUrl3 + "\n"; 72 hash_string + "\n" + kUrl1 + "\n" + kUrl2 + "\n" + kUrl3 + "\n";
73 scoped_refptr<MockSafeBrowsingService> sb_service( 73 scoped_refptr<MockSafeBrowsingService> sb_service(
74 new MockSafeBrowsingService); 74 new MockSafeBrowsingService);
75 EXPECT_CALL(*sb_service.get(), 75 EXPECT_CALL(*sb_service.get(),
76 ReportSafeBrowsingHit(GURL(kUrl3), GURL(kUrl1), GURL(kRefUrl), true, 76 ReportSafeBrowsingHit(GURL(kUrl3), GURL(kUrl1), GURL(kRefUrl), true,
77 SafeBrowsingService::BINARY_MALWARE_HASH, 77 SafeBrowsingService::BINARY_MALWARE_HASH,
78 expected_post)); 78 expected_post, true));
79 std::vector<GURL> url_chain; 79 std::vector<GURL> url_chain;
80 url_chain.push_back(GURL(kUrl1)); 80 url_chain.push_back(GURL(kUrl1));
81 url_chain.push_back(GURL(kUrl2)); 81 url_chain.push_back(GURL(kUrl2));
82 url_chain.push_back(GURL(kUrl3)); 82 url_chain.push_back(GURL(kUrl3));
83 83
84 scoped_refptr<DownloadSBClient> client( 84 scoped_refptr<DownloadSBClient> client(
85 new DownloadSBClient(1, url_chain, GURL(kRefUrl))); 85 new DownloadSBClient(1, url_chain, GURL(kRefUrl), true));
86 client->SetSBService(sb_service.get()); 86 client->SetSBService(sb_service.get());
87 87
88 client->ReportMalware(SafeBrowsingService::BINARY_MALWARE_HASH, hash_data); 88 client->ReportMalware(SafeBrowsingService::BINARY_MALWARE_HASH, hash_data);
89 } 89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698