OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chrome/browser/password_manager/password_manager_metrics_util.h" | |
6 | |
7 #include <iterator> | |
8 #include <map> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 TEST(PasswordManagerTest, MonitoredDomainGroupTest) { | |
14 std::string domain_name; | |
15 const char* const kMonitoredWebsite[] = { | |
16 "https://www.google.com", | |
17 "https://www.yahoo.com", | |
18 "https://www.baidu.com", | |
19 "https://www.wikipedia.org", | |
20 "https://www.linkedin.com", | |
21 "https://www.twitter.com", | |
22 "https://www.live.com", | |
23 "https://www.amazon.com", | |
24 "https://www.ebay.com", | |
25 "https://www.tumblr.com", | |
26 }; | |
27 const size_t kMonitoredWebsiteLength = arraysize(kMonitoredWebsite); | |
28 | |
29 domain_name = password_manager_metrics_util::MonitoredDomainGroup( | |
30 "https://www.linkedin.com"); | |
31 EXPECT_FALSE(domain_name.empty()); | |
32 domain_name = password_manager_metrics_util::MonitoredDomainGroup( | |
33 "https://www.amazon.com"); | |
34 EXPECT_FALSE(domain_name.empty()); | |
35 domain_name = password_manager_metrics_util::MonitoredDomainGroup( | |
36 "https://www.facebook.com"); | |
37 EXPECT_TRUE(domain_name.empty()); | |
38 domain_name = password_manager_metrics_util::MonitoredDomainGroup( | |
39 "http://wikipedia.org"); | |
40 EXPECT_FALSE(domain_name.empty()); | |
41 domain_name = password_manager_metrics_util::MonitoredDomainGroup( | |
42 "http://thisisnotwikipedia.org"); | |
43 EXPECT_TRUE(domain_name.empty()); | |
44 | |
45 // The |groups| map contains the group name and the number of times | |
46 // it get assigned. | |
47 std::map<std::string, unsigned int> groups; | |
vabr (Chromium)
2013/09/11 17:31:24
nit: It could be better if the rest of this test i
jdomingos
2013/09/11 19:15:28
Done.
| |
48 | |
49 // Provide all possible values of the group id parameter for each monitored | |
50 // website. | |
51 for (size_t i = 0; i < kMonitoredWebsiteLength; ++i) { | |
52 for (size_t j = 0; j < password_manager_metrics_util::kGroupsPerDomain; | |
53 j++) { | |
54 password_manager_metrics_util::setGroupId(j); | |
55 ++groups[password_manager_metrics_util::MonitoredDomainGroup( | |
56 kMonitoredWebsite[i])]; | |
57 } | |
58 } | |
59 | |
60 // Check if all groups get assigned the same number of time. | |
61 unsigned int number_of_assignemt = groups["group_1"]; | |
vabr (Chromium)
2013/09/11 17:31:24
typo (assignemt)
jdomingos
2013/09/11 19:15:28
Done.
| |
62 for (std::map<std::string, unsigned int>::iterator it = groups.begin(); | |
63 it != groups.end(); ++it) { | |
64 EXPECT_EQ(it->second, number_of_assignemt); | |
vabr (Chromium)
2013/09/11 17:31:24
nit: Adding
<< " group name = " << it->first
might
jdomingos
2013/09/11 19:15:28
Done.
| |
65 } | |
66 } | |
OLD | NEW |