Chromium Code Reviews| Index: chrome/browser/password_manager/password_manager_metrics_util_unittest.cc |
| diff --git a/chrome/browser/password_manager/password_manager_metrics_util_unittest.cc b/chrome/browser/password_manager/password_manager_metrics_util_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bb6351d13cb47cc9a62741e2706a3792346eb412 |
| --- /dev/null |
| +++ b/chrome/browser/password_manager/password_manager_metrics_util_unittest.cc |
| @@ -0,0 +1,66 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/password_manager/password_manager_metrics_util.h" |
| + |
| +#include <iterator> |
| +#include <map> |
| + |
| +#include "base/basictypes.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +TEST(PasswordManagerTest, MonitoredDomainGroupTest) { |
| + std::string domain_name; |
| + const char* const kMonitoredWebsite[] = { |
| + "https://www.google.com", |
| + "https://www.yahoo.com", |
| + "https://www.baidu.com", |
| + "https://www.wikipedia.org", |
| + "https://www.linkedin.com", |
| + "https://www.twitter.com", |
| + "https://www.live.com", |
| + "https://www.amazon.com", |
| + "https://www.ebay.com", |
| + "https://www.tumblr.com", |
| + }; |
| + const size_t kMonitoredWebsiteLength = arraysize(kMonitoredWebsite); |
| + |
| + domain_name = password_manager_metrics_util::MonitoredDomainGroup( |
| + "https://www.linkedin.com"); |
| + EXPECT_FALSE(domain_name.empty()); |
| + domain_name = password_manager_metrics_util::MonitoredDomainGroup( |
| + "https://www.amazon.com"); |
| + EXPECT_FALSE(domain_name.empty()); |
| + domain_name = password_manager_metrics_util::MonitoredDomainGroup( |
| + "https://www.facebook.com"); |
| + EXPECT_TRUE(domain_name.empty()); |
| + domain_name = password_manager_metrics_util::MonitoredDomainGroup( |
| + "http://wikipedia.org"); |
| + EXPECT_FALSE(domain_name.empty()); |
| + domain_name = password_manager_metrics_util::MonitoredDomainGroup( |
| + "http://thisisnotwikipedia.org"); |
| + EXPECT_TRUE(domain_name.empty()); |
| + |
| + // The |groups| map contains the group name and the number of times |
| + // it get assigned. |
| + 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.
|
| + |
| + // Provide all possible values of the group id parameter for each monitored |
| + // website. |
| + for (size_t i = 0; i < kMonitoredWebsiteLength; ++i) { |
| + for (size_t j = 0; j < password_manager_metrics_util::kGroupsPerDomain; |
| + j++) { |
| + password_manager_metrics_util::setGroupId(j); |
| + ++groups[password_manager_metrics_util::MonitoredDomainGroup( |
| + kMonitoredWebsite[i])]; |
| + } |
| + } |
| + |
| + // Check if all groups get assigned the same number of time. |
| + 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.
|
| + for (std::map<std::string, unsigned int>::iterator it = groups.begin(); |
| + it != groups.end(); ++it) { |
| + 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.
|
| + } |
| +} |