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, MonitoredDomainGroupAssigmentTest) { | |
14 const char* const kMonitoredWebsite[] = { | |
Ilya Sherman
2013/09/12 04:45:45
nit: kMonitoredWebsites (plural)
jdomingos
2013/09/12 12:01:01
Done.
| |
15 "https://www.google.com", | |
16 "https://www.yahoo.com", | |
17 "https://www.baidu.com", | |
18 "https://www.wikipedia.org", | |
19 "https://www.linkedin.com", | |
20 "https://www.twitter.com", | |
21 "https://www.live.com", | |
22 "https://www.amazon.com", | |
23 "https://www.ebay.com", | |
24 "https://www.tumblr.com", | |
25 }; | |
26 const size_t kMonitoredWebsiteLength = arraysize(kMonitoredWebsite); | |
27 | |
28 // The |groups| map contains the group id and the number of times | |
29 // it get assigned. | |
30 std::map<unsigned int, unsigned int> groups; | |
Ilya Sherman
2013/09/12 04:45:45
Please always use "size_t" rather than "unsigned i
jdomingos
2013/09/12 12:01:01
Done.
| |
31 | |
32 // Provide all possible values of the group id parameter for each monitored | |
33 // website. | |
34 for (size_t i = 0; i < kMonitoredWebsiteLength; ++i) { | |
35 for (size_t j = 0; j < password_manager_metrics_util::kGroupsPerDomain; | |
36 j++) { | |
Ilya Sherman
2013/09/12 04:45:45
nit: ++j
jdomingos
2013/09/12 12:01:01
Done.
| |
37 password_manager_metrics_util::SetRandomIdForTesting(j); | |
38 ++groups[password_manager_metrics_util::MonitoredDomainGroupId( | |
39 kMonitoredWebsite[i])]; | |
40 } | |
41 } | |
42 | |
43 // Check if all groups get assigned the same number of time. | |
Ilya Sherman
2013/09/12 04:45:45
nit: "time" -> "times"
jdomingos
2013/09/12 12:01:01
Done.
| |
44 unsigned int number_of_assigment = groups[1]; | |
Ilya Sherman
2013/09/12 04:45:45
Why groups[1] rather than, say, groups[0] or group
jdomingos
2013/09/12 12:01:01
Done.
| |
45 for (std::map<unsigned int, unsigned int>::iterator it = groups.begin(); | |
46 it != groups.end(); ++it) { | |
47 EXPECT_EQ(it->second, number_of_assigment) << " group id = " << it->first; | |
48 } | |
49 } | |
50 | |
51 TEST(PasswordManagerTest, MonitoredDomainGroupTest) { | |
52 unsigned int group_id; | |
53 | |
54 group_id = password_manager_metrics_util::MonitoredDomainGroupId( | |
55 "https://www.linkedin.com"); | |
56 EXPECT_TRUE(group_id > 0); | |
Ilya Sherman
2013/09/12 04:45:45
nit: For readability's sake, it might be helpful t
vabr (Chromium)
2013/09/12 08:51:04
Also, this is better written as
EXPECT_GT(group_id
jdomingos
2013/09/12 12:01:01
Done.
jdomingos
2013/09/12 12:01:01
Done.
| |
57 group_id = password_manager_metrics_util::MonitoredDomainGroupId( | |
58 "https://www.amazon.com"); | |
59 EXPECT_TRUE(group_id > 0); | |
60 group_id = password_manager_metrics_util::MonitoredDomainGroupId( | |
61 "https://www.facebook.com"); | |
62 EXPECT_TRUE(group_id == 0); | |
63 group_id = password_manager_metrics_util::MonitoredDomainGroupId( | |
64 "http://wikipedia.org"); | |
65 EXPECT_TRUE(group_id > 0); | |
66 group_id = password_manager_metrics_util::MonitoredDomainGroupId( | |
67 "http://thisisnotwikipedia.org"); | |
68 EXPECT_TRUE(group_id == 0); | |
69 } | |
OLD | NEW |