NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / password_manager / password_manager_metrics_util_unittest.cc
blob5efcbd21633b231b8fecbdb4354e8714a304e4d4
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"
7 #include <iterator>
8 #include <map>
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 "components/password_manager/core/common/password_manager_pref_names.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 class PasswordManagerMetricsUtilTest : public testing::Test {
19 public:
20 PasswordManagerMetricsUtilTest() {}
22 protected:
23 bool IsMonitored(const char* url_host) {
24 size_t group_id = password_manager_metrics_util::MonitoredDomainGroupId(
25 url_host, profile_.GetPrefs());
26 return group_id > 0;
29 TestingProfile profile_;
32 TEST_F(PasswordManagerMetricsUtilTest, MonitoredDomainGroupAssigmentTest) {
33 const char* const kMonitoredWebsites[] = {
34 "https://www.google.com",
35 "https://www.yahoo.com",
36 "https://www.baidu.com",
37 "https://www.wikipedia.org",
38 "https://www.linkedin.com",
39 "https://www.twitter.com",
40 "https://www.facebook.com",
41 "https://www.amazon.com",
42 "https://www.ebay.com",
43 "https://www.tumblr.com",
45 const size_t kMonitoredWebsitesLength = arraysize(kMonitoredWebsites);
47 // The |groups| map contains the group id and the number of times
48 // it get assigned.
49 std::map<size_t, size_t> groups;
51 // Provide all possible values of the group id parameter for each monitored
52 // website.
53 for (size_t i = 0; i < kMonitoredWebsitesLength; ++i) {
54 for (size_t j = 0; j < password_manager_metrics_util::kGroupsPerDomain;
55 ++j) {
56 { // Set the group index for domain |i| to |j|.
57 ListPrefUpdate group_indices(profile_.GetPrefs(),
58 prefs::kPasswordManagerGroupsForDomains);
59 group_indices->Set(i, new base::FundamentalValue(static_cast<int>(j)));
60 } // At the end of the scope the prefs get updated.
62 ++groups[password_manager_metrics_util::MonitoredDomainGroupId(
63 kMonitoredWebsites[i], profile_.GetPrefs())];
67 // Check if all groups get assigned the same number of times.
68 size_t number_of_assigment = groups.begin()->second;
69 for (std::map<size_t, size_t>::iterator it = groups.begin();
70 it != groups.end(); ++it) {
71 EXPECT_EQ(it->second, number_of_assigment) << " group id = " << it->first;
75 TEST_F(PasswordManagerMetricsUtilTest, MonitoredDomainGroupTest) {
76 EXPECT_TRUE(IsMonitored("https://www.linkedin.com"));
77 EXPECT_TRUE(IsMonitored("https://www.amazon.com"));
78 EXPECT_TRUE(IsMonitored("https://www.facebook.com"));
79 EXPECT_TRUE(IsMonitored("http://wikipedia.org"));
80 EXPECT_FALSE(IsMonitored("http://thisisnotwikipedia.org"));