| OLD | NEW |
| (Empty) |
| 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/tracked_preference_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 | |
| 17 incident->mutable_tracked_preference()->set_path("foo"); | |
| 18 incident->mutable_tracked_preference()->set_atomic_value("bar"); | |
| 19 incident->mutable_tracked_preference()->set_value_state( | |
| 20 safe_browsing:: | |
| 21 ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState
_CLEARED); | |
| 22 return incident.Pass(); | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 // Tests that GetKey returns the preference path. | |
| 28 TEST(GetTrackedPreferenceIncidentKey, KeyIsPath) { | |
| 29 safe_browsing::ClientIncidentReport_IncidentData incident; | |
| 30 | |
| 31 incident.mutable_tracked_preference()->set_path("foo"); | |
| 32 ASSERT_EQ(std::string("foo"), | |
| 33 safe_browsing::GetTrackedPreferenceIncidentKey(incident)); | |
| 34 } | |
| 35 | |
| 36 // Tests that GetDigest returns the same value for the same incident. | |
| 37 TEST(GetTrackedPreferenceIncidentDigest, SameIncidentSameDigest) { | |
| 38 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident( | |
| 39 MakeIncident()); | |
| 40 | |
| 41 uint32_t digest = | |
| 42 safe_browsing::GetTrackedPreferenceIncidentDigest(*incident); | |
| 43 ASSERT_EQ(digest, | |
| 44 safe_browsing::GetTrackedPreferenceIncidentDigest(*MakeIncident())); | |
| 45 } | |
| 46 | |
| 47 // Tests that GetDigest returns the same value for the same incident. | |
| 48 TEST(GetTrackedPreferenceIncidentDigest, DifferentIncidentDifferentDigest) { | |
| 49 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident( | |
| 50 MakeIncident()); | |
| 51 | |
| 52 uint32_t digest = | |
| 53 safe_browsing::GetTrackedPreferenceIncidentDigest(*incident); | |
| 54 | |
| 55 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident2( | |
| 56 MakeIncident()); | |
| 57 incident2->mutable_tracked_preference()->set_value_state( | |
| 58 safe_browsing:: | |
| 59 ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState
_CHANGED); | |
| 60 | |
| 61 ASSERT_NE(digest, | |
| 62 safe_browsing::GetTrackedPreferenceIncidentDigest(*incident2)); | |
| 63 } | |
| OLD | NEW |