1 // Copyright 2013 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/password_manager/password_manager_metrics_util.h"
10 #include "base/basictypes.h"
11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "base/values.h"
13 #include "chrome/common/pref_names.h"
14 #include "chrome/test/base/testing_profile.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 class PasswordManagerMetricsUtilTest
: public testing::Test
{
19 PasswordManagerMetricsUtilTest() {}
22 bool IsMonitored(const char* url_host
) {
23 size_t group_id
= password_manager_metrics_util::MonitoredDomainGroupId(
24 url_host
, profile_
.GetPrefs());
28 TestingProfile profile_
;
31 TEST_F(PasswordManagerMetricsUtilTest
, MonitoredDomainGroupAssigmentTest
) {
32 const char* const kMonitoredWebsites
[] = {
33 "https://www.google.com",
34 "https://www.yahoo.com",
35 "https://www.baidu.com",
36 "https://www.wikipedia.org",
37 "https://www.linkedin.com",
38 "https://www.twitter.com",
39 "https://www.facebook.com",
40 "https://www.amazon.com",
41 "https://www.ebay.com",
42 "https://www.tumblr.com",
44 const size_t kMonitoredWebsitesLength
= arraysize(kMonitoredWebsites
);
46 // The |groups| map contains the group id and the number of times
48 std::map
<size_t, size_t> groups
;
50 // Provide all possible values of the group id parameter for each monitored
52 for (size_t i
= 0; i
< kMonitoredWebsitesLength
; ++i
) {
53 for (size_t j
= 0; j
< password_manager_metrics_util::kGroupsPerDomain
;
55 { // Set the group index for domain |i| to |j|.
56 ListPrefUpdate
group_indices(profile_
.GetPrefs(),
57 prefs::kPasswordManagerGroupsForDomains
);
58 group_indices
->Set(i
, new base::FundamentalValue(static_cast<int>(j
)));
59 } // At the end of the scope the prefs get updated.
61 ++groups
[password_manager_metrics_util::MonitoredDomainGroupId(
62 kMonitoredWebsites
[i
], profile_
.GetPrefs())];
66 // Check if all groups get assigned the same number of times.
67 size_t number_of_assigment
= groups
.begin()->second
;
68 for (std::map
<size_t, size_t>::iterator it
= groups
.begin();
69 it
!= groups
.end(); ++it
) {
70 EXPECT_EQ(it
->second
, number_of_assigment
) << " group id = " << it
->first
;
74 TEST_F(PasswordManagerMetricsUtilTest
, MonitoredDomainGroupTest
) {
75 EXPECT_TRUE(IsMonitored("https://www.linkedin.com"));
76 EXPECT_TRUE(IsMonitored("https://www.amazon.com"));
77 EXPECT_TRUE(IsMonitored("https://www.facebook.com"));
78 EXPECT_TRUE(IsMonitored("http://wikipedia.org"));
79 EXPECT_FALSE(IsMonitored("http://thisisnotwikipedia.org"));