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 namespace { |
| 14 |
| 15 bool IsMonitored(const char* url_host) { |
| 16 return password_manager_metrics_util::MonitoredDomainGroupId(url_host) > 0; |
| 17 } |
| 18 |
| 19 } // namespace |
| 20 |
| 21 TEST(PasswordManagerTest, MonitoredDomainGroupAssigmentTest) { |
| 22 const char* const kMonitoredWebsites[] = { |
| 23 "https://www.google.com", |
| 24 "https://www.yahoo.com", |
| 25 "https://www.baidu.com", |
| 26 "https://www.wikipedia.org", |
| 27 "https://www.linkedin.com", |
| 28 "https://www.twitter.com", |
| 29 "https://www.live.com", |
| 30 "https://www.amazon.com", |
| 31 "https://www.ebay.com", |
| 32 "https://www.tumblr.com", |
| 33 }; |
| 34 const size_t kMonitoredWebsitesLength = arraysize(kMonitoredWebsites); |
| 35 |
| 36 // The |groups| map contains the group id and the number of times |
| 37 // it get assigned. |
| 38 std::map<size_t, size_t> groups; |
| 39 |
| 40 // Provide all possible values of the group id parameter for each monitored |
| 41 // website. |
| 42 for (size_t i = 0; i < kMonitoredWebsitesLength; ++i) { |
| 43 for (size_t j = 0; j < password_manager_metrics_util::kGroupsPerDomain; |
| 44 ++j) { |
| 45 password_manager_metrics_util::SetRandomIdForTesting(j); |
| 46 ++groups[password_manager_metrics_util::MonitoredDomainGroupId( |
| 47 kMonitoredWebsites[i])]; |
| 48 } |
| 49 } |
| 50 |
| 51 // Check if all groups get assigned the same number of times. |
| 52 size_t number_of_assigment = groups.begin()->second; |
| 53 for (std::map<size_t, size_t>::iterator it = groups.begin(); |
| 54 it != groups.end(); ++it) { |
| 55 EXPECT_EQ(it->second, number_of_assigment) << " group id = " << it->first; |
| 56 } |
| 57 } |
| 58 |
| 59 TEST(PasswordManagerTest, MonitoredDomainGroupTest) { |
| 60 EXPECT_TRUE(IsMonitored("https://www.linkedin.com")); |
| 61 EXPECT_TRUE(IsMonitored("https://www.amazon.com")); |
| 62 EXPECT_FALSE(IsMonitored("https://www.facebook.com")); |
| 63 EXPECT_TRUE(IsMonitored("http://wikipedia.org")); |
| 64 EXPECT_FALSE(IsMonitored("http://thisisnotwikipedia.org")); |
| 65 } |
OLD | NEW |