| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/autofill_data_model.h" | 5 #include "components/autofill/core/browser/autofill_data_model.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 model.set_origin(kSettingsOrigin); | 64 model.set_origin(kSettingsOrigin); |
| 65 EXPECT_TRUE(model.IsVerified()); | 65 EXPECT_TRUE(model.IsVerified()); |
| 66 | 66 |
| 67 model.set_origin("Some gibberish string"); | 67 model.set_origin("Some gibberish string"); |
| 68 EXPECT_TRUE(model.IsVerified()); | 68 EXPECT_TRUE(model.IsVerified()); |
| 69 | 69 |
| 70 model.set_origin(std::string()); | 70 model.set_origin(std::string()); |
| 71 EXPECT_FALSE(model.IsVerified()); | 71 EXPECT_FALSE(model.IsVerified()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 TEST(AutofillDataModelTest, CompareFrecency) { | 74 enum Expectation { GREATER, LESS }; |
| 75 base::Time now = base::Time::Now(); | 75 struct CompareFrecencyTestCase { |
| 76 enum Expectation { GREATER, LESS }; | 76 const std::string guid_a; |
| 77 const int use_count_a; |
| 78 const base::Time use_date_a; |
| 79 const std::string guid_b; |
| 80 const int use_count_b; |
| 81 const base::Time use_date_b; |
| 82 Expectation expectation; |
| 83 }; |
| 77 | 84 |
| 78 struct { | 85 base::Time now = base::Time::Now(); |
| 79 const std::string guid_a; | |
| 80 const int use_count_a; | |
| 81 const base::Time use_date_a; | |
| 82 const std::string guid_b; | |
| 83 const int use_count_b; | |
| 84 const base::Time use_date_b; | |
| 85 Expectation expectation; | |
| 86 } test_cases[] = { | |
| 87 // Same frecency, model_a has a smaller GUID (tie breaker). | |
| 88 {"guid_a", 8, now, "guid_b", 8, now, LESS}, | |
| 89 // Same recency, model_a has a bigger frequency. | |
| 90 {"guid_a", 10, now, "guid_b", 8, now, GREATER}, | |
| 91 // Same recency, model_a has a smaller frequency. | |
| 92 {"guid_a", 8, now, "guid_b", 10, now, LESS}, | |
| 93 // Same frequency, model_a is more recent. | |
| 94 {"guid_a", 8, now, "guid_b", 8, now - base::TimeDelta::FromDays(1), | |
| 95 GREATER}, | |
| 96 // Same frequency, model_a is less recent. | |
| 97 {"guid_a", 8, now - base::TimeDelta::FromDays(1), "guid_b", 8, now, LESS}, | |
| 98 // Special case: occasional profiles. A profile with relatively low usage | |
| 99 // and used recently (model_b) should not rank higher than a more used | |
| 100 // profile that has been unused for a short amount of time (model_a). | |
| 101 {"guid_a", 300, now - base::TimeDelta::FromDays(5), "guid_b", 10, | |
| 102 now - base::TimeDelta::FromDays(1), GREATER}, | |
| 103 // Special case: moving. A new profile used frequently (model_b) should | |
| 104 // rank higher than a profile with more usage that has not been used for a | |
| 105 // while (model_a). | |
| 106 {"guid_a", 300, now - base::TimeDelta::FromDays(15), "guid_b", 10, | |
| 107 now - base::TimeDelta::FromDays(1), LESS}, | |
| 108 }; | |
| 109 | 86 |
| 110 for (auto test_case : test_cases) { | 87 class CompareFrecencyTest |
| 111 TestAutofillDataModel model_a(test_case.guid_a, test_case.use_count_a, | 88 : public testing::TestWithParam<CompareFrecencyTestCase> {}; |
| 112 test_case.use_date_a); | |
| 113 TestAutofillDataModel model_b(test_case.guid_b, test_case.use_count_b, | |
| 114 test_case.use_date_b); | |
| 115 | 89 |
| 116 EXPECT_EQ(test_case.expectation == GREATER, | 90 TEST_P(CompareFrecencyTest, CompareFrecency) { |
| 117 model_a.CompareFrecency(&model_b, now)); | 91 auto test_case = GetParam(); |
| 118 EXPECT_NE(test_case.expectation == GREATER, | 92 TestAutofillDataModel model_a(test_case.guid_a, test_case.use_count_a, |
| 119 model_b.CompareFrecency(&model_a, now)); | 93 test_case.use_date_a); |
| 120 } | 94 TestAutofillDataModel model_b(test_case.guid_b, test_case.use_count_b, |
| 95 test_case.use_date_b); |
| 96 |
| 97 EXPECT_EQ(test_case.expectation == GREATER, |
| 98 model_a.CompareFrecency(&model_b, now)); |
| 99 EXPECT_NE(test_case.expectation == GREATER, |
| 100 model_b.CompareFrecency(&model_a, now)); |
| 121 } | 101 } |
| 122 | 102 |
| 103 INSTANTIATE_TEST_CASE_P( |
| 104 AutofillDataModelTest, |
| 105 CompareFrecencyTest, |
| 106 testing::Values( |
| 107 // Same frecency, model_a has a smaller GUID (tie breaker). |
| 108 CompareFrecencyTestCase{"guid_a", 8, now, "guid_b", 8, now, LESS}, |
| 109 // Same recency, model_a has a bigger frequency. |
| 110 CompareFrecencyTestCase{"guid_a", 10, now, "guid_b", 8, now, GREATER}, |
| 111 // Same recency, model_a has a smaller frequency. |
| 112 CompareFrecencyTestCase{"guid_a", 8, now, "guid_b", 10, now, LESS}, |
| 113 // Same frequency, model_a is more recent. |
| 114 CompareFrecencyTestCase{"guid_a", 8, now, "guid_b", 8, |
| 115 now - base::TimeDelta::FromDays(1), GREATER}, |
| 116 // Same frequency, model_a is less recent. |
| 117 CompareFrecencyTestCase{"guid_a", 8, now - base::TimeDelta::FromDays(1), |
| 118 "guid_b", 8, now, LESS}, |
| 119 // Special case: occasional profiles. A profile with relatively low |
| 120 // usage and used recently (model_b) should not rank higher than a more |
| 121 // used profile that has been unused for a short amount of time |
| 122 // (model_a). |
| 123 CompareFrecencyTestCase{ |
| 124 "guid_a", 300, now - base::TimeDelta::FromDays(5), "guid_b", 10, |
| 125 now - base::TimeDelta::FromDays(1), GREATER}, |
| 126 // Special case: moving. A new profile used frequently (model_b) should |
| 127 // rank higher than a profile with more usage that has not been used for |
| 128 // a while (model_a). |
| 129 CompareFrecencyTestCase{"guid_a", 300, |
| 130 now - base::TimeDelta::FromDays(15), "guid_b", |
| 131 10, now - base::TimeDelta::FromDays(1), LESS})); |
| 132 |
| 123 } // namespace autofill | 133 } // namespace autofill |
| OLD | NEW |