| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/message_loop.h" | |
| 6 #include "chrome/browser/download/download_safe_browsing_client.h" | |
| 7 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
| 8 #include "content/test/test_browser_thread.h" | |
| 9 #include "testing/gmock/include/gmock/gmock.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 using content::BrowserThread; | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 const char* kUrl1 = "http://127.0.0.1/"; | |
| 17 const char* kUrl2 = "http://127.0.0.1/two"; | |
| 18 const char* kUrl3 = "http://127.0.0.1/three"; | |
| 19 const char* kRefUrl = "http://127.0.0.1/referrer"; | |
| 20 | |
| 21 class MockSafeBrowsingService : public SafeBrowsingService { | |
| 22 public: | |
| 23 MockSafeBrowsingService() {} | |
| 24 virtual ~MockSafeBrowsingService() {} | |
| 25 | |
| 26 MOCK_METHOD6(ReportSafeBrowsingHit, | |
| 27 void(const GURL&, const GURL&, const GURL&, bool, UrlCheckResult, | |
| 28 const std::string&)); | |
| 29 | |
| 30 private: | |
| 31 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingService); | |
| 32 }; | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 class DownloadSBClientTest : public testing::Test { | |
| 37 public: | |
| 38 DownloadSBClientTest() : | |
| 39 ui_thread_(BrowserThread::UI, &loop_) { | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 MessageLoop loop_; | |
| 44 | |
| 45 // UI thread to satisfy debug checks in DownloadSBClient. | |
| 46 content::TestBrowserThread ui_thread_; | |
| 47 }; | |
| 48 | |
| 49 TEST_F(DownloadSBClientTest, UrlHit) { | |
| 50 std::string expected_post = | |
| 51 std::string(kUrl1) + "\n" + kUrl2 + "\n" + kUrl3 + "\n"; | |
| 52 scoped_refptr<MockSafeBrowsingService> sb_service( | |
| 53 new MockSafeBrowsingService); | |
| 54 EXPECT_CALL(*sb_service.get(), | |
| 55 ReportSafeBrowsingHit(GURL(kUrl3), GURL(kUrl1), GURL(kRefUrl), true, | |
| 56 SafeBrowsingService::BINARY_MALWARE_URL, | |
| 57 expected_post)); | |
| 58 std::vector<GURL> url_chain; | |
| 59 url_chain.push_back(GURL(kUrl1)); | |
| 60 url_chain.push_back(GURL(kUrl2)); | |
| 61 url_chain.push_back(GURL(kUrl3)); | |
| 62 | |
| 63 scoped_refptr<DownloadSBClient> client( | |
| 64 new DownloadSBClient(1, url_chain, GURL(kRefUrl), true)); | |
| 65 client->SetSBService(sb_service.get()); | |
| 66 | |
| 67 client->ReportMalware(SafeBrowsingService::BINARY_MALWARE_URL, ""); | |
| 68 } | |
| 69 | |
| 70 TEST_F(DownloadSBClientTest, DigestHit) { | |
| 71 std::string hash_data = "\xDE\xAD\xBE\xEF"; | |
| 72 std::string hash_string = "DEADBEEF"; | |
| 73 std::string expected_post = | |
| 74 hash_string + "\n" + kUrl1 + "\n" + kUrl2 + "\n" + kUrl3 + "\n"; | |
| 75 scoped_refptr<MockSafeBrowsingService> sb_service( | |
| 76 new MockSafeBrowsingService); | |
| 77 EXPECT_CALL(*sb_service.get(), | |
| 78 ReportSafeBrowsingHit(GURL(kUrl3), GURL(kUrl1), GURL(kRefUrl), true, | |
| 79 SafeBrowsingService::BINARY_MALWARE_HASH, | |
| 80 expected_post)); | |
| 81 std::vector<GURL> url_chain; | |
| 82 url_chain.push_back(GURL(kUrl1)); | |
| 83 url_chain.push_back(GURL(kUrl2)); | |
| 84 url_chain.push_back(GURL(kUrl3)); | |
| 85 | |
| 86 scoped_refptr<DownloadSBClient> client( | |
| 87 new DownloadSBClient(1, url_chain, GURL(kRefUrl), true)); | |
| 88 client->SetSBService(sb_service.get()); | |
| 89 | |
| 90 client->ReportMalware(SafeBrowsingService::BINARY_MALWARE_HASH, hash_data); | |
| 91 } | |
| OLD | NEW |