Home | History | Annotate | Download | only in incident_reporting
      1 // Copyright 2014 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 "chrome/browser/safe_browsing/incident_reporting/blacklist_load_incident_handlers.h"
      6 
      7 #include "base/memory/scoped_ptr.h"
      8 #include "chrome/common/safe_browsing/csd.pb.h"
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 
     11 namespace {
     12 
     13 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> MakeIncident() {
     14   scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident(
     15       new safe_browsing::ClientIncidentReport_IncidentData);
     16   incident->mutable_blacklist_load()->set_path("foo");
     17   return incident.Pass();
     18 }
     19 
     20 }  // namespace
     21 
     22 // Tests that GetKey returns the dll path.
     23 TEST(GetBlacklistLoadIncidentKey, KeyIsPath) {
     24   safe_browsing::ClientIncidentReport_IncidentData incident;
     25 
     26   incident.mutable_blacklist_load()->set_path("foo");
     27   ASSERT_EQ(std::string("foo"),
     28             safe_browsing::GetBlacklistLoadIncidentKey(incident));
     29 }
     30 
     31 // Tests that GetDigest returns the same value for the same incident.
     32 TEST(GetBlacklistLoadIncidentDigest, SameIncidentSameDigest) {
     33   scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident(
     34       MakeIncident());
     35 
     36   uint32_t digest = safe_browsing::GetBlacklistLoadIncidentDigest(*incident);
     37   ASSERT_EQ(digest,
     38             safe_browsing::GetBlacklistLoadIncidentDigest(*MakeIncident()));
     39 }
     40 
     41 // Tests that GetDigest returns different values for different incidents.
     42 TEST(GetBlacklistLoadIncidentDigest, DifferentIncidentDifferentDigest) {
     43   scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident(
     44       MakeIncident());
     45   scoped_ptr<safe_browsing::ClientDownloadRequest_Digests> digest_proto(
     46       new safe_browsing::ClientDownloadRequest_Digests);
     47   digest_proto->set_sha256("37");
     48   incident->mutable_blacklist_load()->set_allocated_digest(
     49       digest_proto.release());
     50 
     51   scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident2(
     52       MakeIncident());
     53   scoped_ptr<safe_browsing::ClientDownloadRequest_Digests> digest_proto2(
     54       new safe_browsing::ClientDownloadRequest_Digests);
     55   digest_proto2->set_sha256("42");
     56   incident2->mutable_blacklist_load()->set_allocated_digest(
     57       digest_proto2.release());
     58 
     59   ASSERT_NE(safe_browsing::GetBlacklistLoadIncidentDigest(*incident),
     60             safe_browsing::GetBlacklistLoadIncidentDigest(*incident2));
     61 }
     62