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 "components/password_manager/core/browser/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/test/base/testing_profile.h"
14 #include "components/password_manager/core/common/password_manager_pref_names.h"
15 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 class PasswordManagerMetricsUtilTest
: public testing::Test
{
20 PasswordManagerMetricsUtilTest() {}
23 bool IsMonitored(const char* url_host
) {
24 size_t group_id
= password_manager::metrics_util::MonitoredDomainGroupId(
25 url_host
, profile_
.GetPrefs());
29 content::TestBrowserThreadBundle thread_bundle_
;
30 TestingProfile profile_
;
33 TEST_F(PasswordManagerMetricsUtilTest
, MonitoredDomainGroupAssigmentTest
) {
34 const char* const kMonitoredWebsites
[] = {
35 "https://www.google.com",
36 "https://www.yahoo.com",
37 "https://www.baidu.com",
38 "https://www.wikipedia.org",
39 "https://www.linkedin.com",
40 "https://www.twitter.com",
41 "https://www.facebook.com",
42 "https://www.amazon.com",
43 "https://www.ebay.com",
44 "https://www.tumblr.com",
46 const size_t kMonitoredWebsitesLength
= arraysize(kMonitoredWebsites
);
48 // The |groups| map contains the group id and the number of times
50 std::map
<size_t, size_t> groups
;
52 // Provide all possible values of the group id parameter for each monitored
54 for (size_t i
= 0; i
< kMonitoredWebsitesLength
; ++i
) {
55 for (size_t j
= 0; j
< password_manager::metrics_util::kGroupsPerDomain
;
57 { // Set the group index for domain |i| to |j|.
58 ListPrefUpdate
group_indices(
60 password_manager::prefs::kPasswordManagerGroupsForDomains
);
61 group_indices
->Set(i
, new base::FundamentalValue(static_cast<int>(j
)));
62 } // At the end of the scope the prefs get updated.
64 ++groups
[password_manager::metrics_util::MonitoredDomainGroupId(
65 kMonitoredWebsites
[i
], profile_
.GetPrefs())];
69 // Check if all groups get assigned the same number of times.
70 size_t number_of_assigment
= groups
.begin()->second
;
71 for (std::map
<size_t, size_t>::iterator it
= groups
.begin();
72 it
!= groups
.end(); ++it
) {
73 EXPECT_EQ(it
->second
, number_of_assigment
) << " group id = " << it
->first
;
77 TEST_F(PasswordManagerMetricsUtilTest
, MonitoredDomainGroupTest
) {
78 EXPECT_TRUE(IsMonitored("https://www.linkedin.com"));
79 EXPECT_TRUE(IsMonitored("https://www.amazon.com"));
80 EXPECT_TRUE(IsMonitored("https://www.facebook.com"));
81 EXPECT_TRUE(IsMonitored("http://wikipedia.org"));
82 EXPECT_FALSE(IsMonitored("http://thisisnotwikipedia.org"));