Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / safe_browsing / incident_reporting / tracked_preference_incident_unittest.cc
blobf729ef31774d0e0d6f1b46b94e016e09a583028a
1 // Copyright 2015 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.
5 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_incident.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/common/safe_browsing/csd.pb.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace safe_browsing {
13 namespace {
15 scoped_ptr<Incident> MakeIncident(bool changed, bool is_personal) {
16 scoped_ptr<ClientIncidentReport_IncidentData_TrackedPreferenceIncident>
17 incident(new ClientIncidentReport_IncidentData_TrackedPreferenceIncident);
19 incident->set_path("foo");
20 incident->set_atomic_value("bar");
21 incident->set_value_state(
22 changed
23 ? ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState_CHANGED
24 : ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState_CLEARED);
25 return make_scoped_ptr(
26 new TrackedPreferenceIncident(incident.Pass(), is_personal));
29 } // namespace
31 TEST(TrackedPreferenceIncident, GetType) {
32 ASSERT_EQ(IncidentType::TRACKED_PREFERENCE,
33 MakeIncident(false, false)->GetType());
36 // Tests that GetKey returns the preference path.
37 TEST(TrackedPreferenceIncident, KeyIsPath) {
38 ASSERT_EQ(std::string("foo"), MakeIncident(false, false)->GetKey());
41 // Tests that GetDigest returns the same value for the same incident.
42 TEST(TrackedPreferenceIncident, SameIncidentSameDigest) {
43 ASSERT_EQ(MakeIncident(false, false)->ComputeDigest(),
44 MakeIncident(false, false)->ComputeDigest());
47 // Tests that GetDigest returns a different value for different incidents.
48 TEST(TrackedPreferenceIncident, DifferentIncidentDifferentDigest) {
49 ASSERT_NE(MakeIncident(false, false)->ComputeDigest(),
50 MakeIncident(true, false)->ComputeDigest());
53 // Tests that values are removed for personal preferences.
54 TEST(TrackedPreferenceIncident, Filter) {
55 scoped_ptr<ClientIncidentReport_IncidentData> impersonal(
56 MakeIncident(false, false)->TakePayload());
57 ASSERT_TRUE(impersonal->tracked_preference().has_atomic_value());
59 scoped_ptr<ClientIncidentReport_IncidentData> personal(
60 MakeIncident(false, true)->TakePayload());
61 ASSERT_FALSE(personal->tracked_preference().has_atomic_value());
64 } // namespace safe_browsing